whale-code 6.5.2 → 6.5.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.
Files changed (2) hide show
  1. package/dist/index.js +26 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38,8 +38,33 @@ const IS_SERVICE_ROLE = !!process.env.SUPABASE_SERVICE_ROLE_KEY;
38
38
  let USER_ID = rawConfig.user_id || null;
39
39
  let USER_EMAIL = rawConfig.email || null;
40
40
  // ============================================================================
41
- // AUTH STATE — tracks whether we can make authenticated API calls
41
+ // AUTH STATE — auto-refresh expired tokens before connecting
42
42
  // ============================================================================
43
+ // If using a user JWT (not service role), check if it needs refreshing
44
+ if (!IS_SERVICE_ROLE && rawConfig.access_token && rawConfig.refresh_token) {
45
+ const now = Math.floor(Date.now() / 1000);
46
+ if (!rawConfig.expires_at || rawConfig.expires_at - 300 < now) {
47
+ console.error("[MCP] Access token expired, refreshing...");
48
+ try {
49
+ const freshToken = await getValidToken();
50
+ if (freshToken) {
51
+ INITIAL_SUPABASE_KEY = freshToken;
52
+ // Reload config to get updated values
53
+ rawConfig = loadConfig();
54
+ USER_ID = rawConfig.user_id || USER_ID;
55
+ USER_EMAIL = rawConfig.email || USER_EMAIL;
56
+ STORE_ID = rawConfig.store_id || STORE_ID;
57
+ console.error("[MCP] Token refreshed successfully");
58
+ }
59
+ else {
60
+ console.error("[MCP] Token refresh failed — run `whale login` to re-authenticate");
61
+ }
62
+ }
63
+ catch (e) {
64
+ console.error("[MCP] Token refresh error:", e.message);
65
+ }
66
+ }
67
+ }
43
68
  let isAuthenticated = !!(SUPABASE_URL && INITIAL_SUPABASE_KEY);
44
69
  let supabase = null;
45
70
  if (isAuthenticated) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whale-code",
3
- "version": "6.5.2",
3
+ "version": "6.5.3",
4
4
  "description": "whale code — local-first AI agent CLI for inventory, orders, and analytics powered by MCP",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",