@townco/core 0.0.84 → 0.0.86
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/dist/auth.d.ts +2 -9
- package/dist/auth.js +6 -31
- package/package.json +2 -2
package/dist/auth.d.ts
CHANGED
|
@@ -47,17 +47,10 @@ export declare function getShedUrl(): string;
|
|
|
47
47
|
export declare function refreshAuthToken(credentials: AuthCredentials): Promise<AuthCredentials>;
|
|
48
48
|
/**
|
|
49
49
|
* Get shed authentication (access token and URL).
|
|
50
|
-
* Tries
|
|
50
|
+
* Tries SHED_API_KEY first, then auth file with automatic token refresh.
|
|
51
51
|
* Returns null if neither is available.
|
|
52
52
|
*/
|
|
53
|
-
export declare function getShedAuth(): {
|
|
54
|
-
accessToken: string;
|
|
55
|
-
shedUrl: string;
|
|
56
|
-
} | null;
|
|
57
|
-
/**
|
|
58
|
-
* Ensure the user is authenticated, refreshing the token if necessary.
|
|
59
|
-
*/
|
|
60
|
-
export declare function ensureAuthenticated(): Promise<{
|
|
53
|
+
export declare function getShedAuth(): Promise<{
|
|
61
54
|
accessToken: string;
|
|
62
55
|
shedUrl: string;
|
|
63
56
|
} | null>;
|
package/dist/auth.js
CHANGED
|
@@ -115,33 +115,11 @@ export async function refreshAuthToken(credentials) {
|
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* Get shed authentication (access token and URL).
|
|
118
|
-
* Tries
|
|
118
|
+
* Tries SHED_API_KEY first, then auth file with automatic token refresh.
|
|
119
119
|
* Returns null if neither is available.
|
|
120
120
|
*/
|
|
121
|
-
export function getShedAuth() {
|
|
122
|
-
//
|
|
123
|
-
const credentials = loadAuthCredentialsFromDisk();
|
|
124
|
-
if (credentials) {
|
|
125
|
-
return {
|
|
126
|
-
accessToken: credentials.access_token,
|
|
127
|
-
shedUrl: credentials.shed_url ?? getShedUrl(),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
// Fall back to SHED_API_KEY
|
|
131
|
-
const apiKey = process.env.SHED_API_KEY;
|
|
132
|
-
if (apiKey) {
|
|
133
|
-
return {
|
|
134
|
-
accessToken: apiKey,
|
|
135
|
-
shedUrl: getShedUrl(),
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Ensure the user is authenticated, refreshing the token if necessary.
|
|
142
|
-
*/
|
|
143
|
-
export async function ensureAuthenticated() {
|
|
144
|
-
// 1. Check SHED_API_KEY (static, no refresh needed)
|
|
121
|
+
export async function getShedAuth() {
|
|
122
|
+
// Check SHED_API_KEY first (static, no refresh needed)
|
|
145
123
|
const apiKey = process.env.SHED_API_KEY;
|
|
146
124
|
if (apiKey) {
|
|
147
125
|
return {
|
|
@@ -149,12 +127,12 @@ export async function ensureAuthenticated() {
|
|
|
149
127
|
shedUrl: getShedUrl(),
|
|
150
128
|
};
|
|
151
129
|
}
|
|
152
|
-
//
|
|
130
|
+
// Check disk credentials
|
|
153
131
|
let credentials = loadAuthCredentialsFromDisk();
|
|
154
132
|
if (!credentials) {
|
|
155
133
|
return null;
|
|
156
134
|
}
|
|
157
|
-
//
|
|
135
|
+
// Check expiry and refresh if needed
|
|
158
136
|
if (isTokenExpired(credentials)) {
|
|
159
137
|
try {
|
|
160
138
|
credentials = await refreshAuthToken(credentials);
|
|
@@ -162,10 +140,7 @@ export async function ensureAuthenticated() {
|
|
|
162
140
|
}
|
|
163
141
|
catch (error) {
|
|
164
142
|
console.warn("Failed to refresh token:", error);
|
|
165
|
-
// If refresh fails,
|
|
166
|
-
// Usually if refresh fails, the session is dead.
|
|
167
|
-
// We'll return null to indicate auth failure (or let the old token fail downstream)
|
|
168
|
-
// But returning null matches "not logged in" semantics.
|
|
143
|
+
// If refresh fails, the session is dead - return null
|
|
169
144
|
return null;
|
|
170
145
|
}
|
|
171
146
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@townco/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.86",
|
|
5
5
|
"description": "core",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@typescript/native-preview": "^7.0.0-dev.20251207.1",
|
|
33
|
-
"@townco/tsconfig": "0.1.
|
|
33
|
+
"@townco/tsconfig": "0.1.105"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsgo",
|