@skhema/cli 0.4.6 → 0.4.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/token-store.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAoFnD,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,iBAAiB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAuC9E;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGtD;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAQ3C"}
1
+ {"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/token-store.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAoFnD,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,iBAAiB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CA6D9E;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGtD;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAQ3C"}
@@ -90,28 +90,51 @@ export async function getStoredCredentials() {
90
90
  const credentials = JSON.parse(data);
91
91
  // Auto-refresh if within buffer of expiry
92
92
  if (credentials.expires_at - Date.now() < TOKEN_REFRESH_BUFFER) {
93
+ let newTokens;
94
+ try {
95
+ newTokens = await refreshAccessToken(credentials.refresh_token);
96
+ }
97
+ catch {
98
+ // Refresh failed. If the access token is still valid (refresh was just
99
+ // the pre-expiry buffer, e.g. a network blip), the credentials remain
100
+ // usable. If it has ALREADY expired, the session is dead (refresh
101
+ // tokens live 7 days) — returning it would present an unusable bearer
102
+ // downstream as a "valid session" and surface as a bare 401 far from
103
+ // the cause. Treat as unauthenticated instead.
104
+ if (credentials.expires_at > Date.now()) {
105
+ return credentials;
106
+ }
107
+ return null;
108
+ }
109
+ // Refresh succeeded — the session is alive. Nothing past this point is
110
+ // allowed to discard it: userinfo is cosmetic (keep the prior identity
111
+ // on failure) and a persist failure still leaves the tokens usable for
112
+ // this invocation.
113
+ const refreshed = {
114
+ ...credentials,
115
+ access_token: newTokens.access_token,
116
+ refresh_token: newTokens.refresh_token,
117
+ expires_at: Date.now() + newTokens.expires_in * 1000,
118
+ scope: newTokens.scope,
119
+ };
93
120
  try {
94
- const newTokens = await refreshAccessToken(credentials.refresh_token);
95
121
  const userInfo = await fetchUserInfo(newTokens.access_token);
96
- const refreshed = {
97
- ...credentials,
98
- access_token: newTokens.access_token,
99
- refresh_token: newTokens.refresh_token,
100
- expires_at: Date.now() + newTokens.expires_in * 1000,
101
- scope: newTokens.scope,
102
- user: {
103
- id: userInfo.sub,
104
- email: userInfo.email,
105
- name: userInfo.name,
106
- },
122
+ refreshed.user = {
123
+ id: userInfo.sub,
124
+ email: userInfo.email,
125
+ name: userInfo.name,
107
126
  };
127
+ }
128
+ catch {
129
+ /* keep the previously stored user */
130
+ }
131
+ try {
108
132
  await storeCredentials(refreshed);
109
- return refreshed;
110
133
  }
111
134
  catch {
112
- // Refresh failed - return stale credentials, caller can handle
113
- return credentials;
135
+ /* still return the in-memory refreshed session */
114
136
  }
137
+ return refreshed;
115
138
  }
116
139
  return credentials;
117
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skhema/cli",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Skhema CLI - Authentication and AI skills management for agent platforms",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",