@mindexec/cli 0.2.208 → 0.2.209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +57 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindexec/cli",
3
- "version": "0.2.208",
3
+ "version": "0.2.209",
4
4
  "description": "MindExec local runtime and bridge CLI",
5
5
  "main": "server.js",
6
6
  "type": "module",
package/server.js CHANGED
@@ -5632,6 +5632,39 @@ function readSupabaseSessionField(source, ...keys) {
5632
5632
  return '';
5633
5633
  }
5634
5634
 
5635
+ function unwrapSupabaseSessionCandidate(value, depth = 0) {
5636
+ if (!value || typeof value !== 'object' || depth > 4) {
5637
+ return value;
5638
+ }
5639
+
5640
+ const directAccessToken = readSupabaseSessionField(value, 'access_token', 'accessToken', 'AccessToken');
5641
+ const directUser = value.user || value.User;
5642
+ if (directAccessToken && directUser) {
5643
+ return value;
5644
+ }
5645
+
5646
+ const candidates = [
5647
+ value.session,
5648
+ value.Session,
5649
+ value.currentSession,
5650
+ value.CurrentSession,
5651
+ value.supabaseSession,
5652
+ value.SupabaseSession,
5653
+ value.authSession,
5654
+ value.AuthSession
5655
+ ];
5656
+ for (const candidate of candidates) {
5657
+ if (candidate && typeof candidate === 'object') {
5658
+ const unwrapped = unwrapSupabaseSessionCandidate(candidate, depth + 1);
5659
+ if (unwrapped && typeof unwrapped === 'object') {
5660
+ return unwrapped;
5661
+ }
5662
+ }
5663
+ }
5664
+
5665
+ return value;
5666
+ }
5667
+
5635
5668
  function parseSupabaseSessionExpiresAtMs(value) {
5636
5669
  if (value === undefined || value === null || String(value).trim() === '') {
5637
5670
  return 0;
@@ -5662,10 +5695,14 @@ function setSupabaseSessionKnownField(session, value, fallbackKey, ...keys) {
5662
5695
 
5663
5696
  function buildRefreshedSupabaseSessionPayload(content, refreshedSession) {
5664
5697
  const existing = JSON.parse(String(content || '{}'));
5698
+ const targetSession = unwrapSupabaseSessionCandidate(existing);
5699
+ const sessionToUpdate = targetSession && typeof targetSession === 'object' ? targetSession : existing;
5665
5700
  const accessToken = String(readSupabaseSessionField(refreshedSession, 'access_token', 'accessToken', 'AccessToken')).trim();
5666
5701
  const refreshToken = String(readSupabaseSessionField(refreshedSession, 'refresh_token', 'refreshToken', 'RefreshToken')).trim()
5702
+ || String(readSupabaseSessionField(sessionToUpdate, 'refresh_token', 'refreshToken', 'RefreshToken')).trim()
5667
5703
  || String(readSupabaseSessionField(existing, 'refresh_token', 'refreshToken', 'RefreshToken')).trim();
5668
5704
  const tokenType = String(readSupabaseSessionField(refreshedSession, 'token_type', 'tokenType', 'TokenType')).trim()
5705
+ || String(readSupabaseSessionField(sessionToUpdate, 'token_type', 'tokenType', 'TokenType')).trim()
5669
5706
  || String(readSupabaseSessionField(existing, 'token_type', 'tokenType', 'TokenType')).trim()
5670
5707
  || 'bearer';
5671
5708
  const expiresInRaw = Number(readSupabaseSessionField(refreshedSession, 'expires_in', 'expiresIn', 'ExpiresIn') || 0);
@@ -5680,21 +5717,21 @@ function buildRefreshedSupabaseSessionPayload(content, refreshedSession) {
5680
5717
  throw error;
5681
5718
  }
5682
5719
 
5683
- setSupabaseSessionKnownField(existing, accessToken, 'access_token', 'access_token', 'accessToken', 'AccessToken');
5684
- setSupabaseSessionKnownField(existing, refreshToken, 'refresh_token', 'refresh_token', 'refreshToken', 'RefreshToken');
5685
- setSupabaseSessionKnownField(existing, tokenType, 'token_type', 'token_type', 'tokenType', 'TokenType');
5686
- setSupabaseSessionKnownField(existing, expiresAtSeconds, 'expires_at', 'expires_at', 'expiresAt', 'ExpiresAt');
5720
+ setSupabaseSessionKnownField(sessionToUpdate, accessToken, 'access_token', 'access_token', 'accessToken', 'AccessToken');
5721
+ setSupabaseSessionKnownField(sessionToUpdate, refreshToken, 'refresh_token', 'refresh_token', 'refreshToken', 'RefreshToken');
5722
+ setSupabaseSessionKnownField(sessionToUpdate, tokenType, 'token_type', 'token_type', 'tokenType', 'TokenType');
5723
+ setSupabaseSessionKnownField(sessionToUpdate, expiresAtSeconds, 'expires_at', 'expires_at', 'expiresAt', 'ExpiresAt');
5687
5724
 
5688
5725
  if (Number.isFinite(expiresInRaw) && expiresInRaw > 0) {
5689
- setSupabaseSessionKnownField(existing, Math.floor(expiresInRaw), 'expires_in', 'expires_in', 'expiresIn', 'ExpiresIn');
5726
+ setSupabaseSessionKnownField(sessionToUpdate, Math.floor(expiresInRaw), 'expires_in', 'expires_in', 'expiresIn', 'ExpiresIn');
5690
5727
  }
5691
5728
 
5692
5729
  const user = refreshedSession?.user || refreshedSession?.User;
5693
5730
  if (user && typeof user === 'object') {
5694
- if (Object.prototype.hasOwnProperty.call(existing, 'User')) {
5695
- existing.User = user;
5731
+ if (Object.prototype.hasOwnProperty.call(sessionToUpdate, 'User')) {
5732
+ sessionToUpdate.User = user;
5696
5733
  } else {
5697
- existing.user = user;
5734
+ sessionToUpdate.user = user;
5698
5735
  }
5699
5736
  }
5700
5737
 
@@ -5704,18 +5741,27 @@ function buildRefreshedSupabaseSessionPayload(content, refreshedSession) {
5704
5741
  function parseSupabaseSessionForRegistry(content) {
5705
5742
  let session = null;
5706
5743
  try {
5707
- session = JSON.parse(String(content || ''));
5744
+ session = unwrapSupabaseSessionCandidate(JSON.parse(String(content || '')));
5708
5745
  } catch {
5709
5746
  return null;
5710
5747
  }
5711
5748
 
5712
5749
  const user = session?.user || session?.User || {};
5713
- const accessToken = String(readSupabaseSessionField(session, 'access_token', 'accessToken', 'AccessToken')).trim();
5750
+ const accessToken = String(readSupabaseSessionField(session, 'access_token', 'accessToken', 'AccessToken', 'token', 'Token')).trim();
5714
5751
  const refreshToken = String(readSupabaseSessionField(session, 'refresh_token', 'refreshToken', 'RefreshToken')).trim();
5715
5752
  const userId = String(
5716
5753
  readSupabaseSessionField(user, 'id', 'Id')
5717
5754
  || readSupabaseSessionField(session, 'user_id', 'userId', 'UserId')).trim();
5718
- const expiresAtMs = parseSupabaseSessionExpiresAtMs(readSupabaseSessionField(session, 'expires_at', 'expiresAt', 'ExpiresAt'));
5755
+ const expiresAtMs = parseSupabaseSessionExpiresAtMs(readSupabaseSessionField(
5756
+ session,
5757
+ 'expires_at',
5758
+ 'expiresAt',
5759
+ 'ExpiresAt',
5760
+ 'expires_at_ms',
5761
+ 'expiresAtMs',
5762
+ 'ExpiresAtMs',
5763
+ 'expiresAtUnixTime',
5764
+ 'ExpiresAtUnixTime'));
5719
5765
 
5720
5766
  if (!accessToken || !userId) {
5721
5767
  return null;