@townco/core 0.0.46 → 0.0.48

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 CHANGED
@@ -11,16 +11,11 @@ export interface AuthCredentials {
11
11
  };
12
12
  shed_url: string;
13
13
  }
14
- /**
15
- * Get the auth file path.
16
- * Uses TOWN_AUTH_PATH env var if set, otherwise defaults to ~/.config/town/auth.json
17
- */
18
- export declare function getAuthFilePath(): string;
19
14
  /**
20
15
  * Load auth credentials from disk.
21
16
  * Returns null if not logged in or file is invalid.
22
17
  */
23
- export declare function loadAuthCredentials(): AuthCredentials | null;
18
+ export declare function loadAuthCredentialsFromDisk(): AuthCredentials | null;
24
19
  /**
25
20
  * Check if access token is expired or about to expire (within 5 minutes)
26
21
  */
@@ -33,7 +28,9 @@ export declare function isLoggedIn(): boolean;
33
28
  * Save auth credentials to disk.
34
29
  * Creates the config directory if it doesn't exist.
35
30
  */
36
- export declare function saveAuthCredentials(credentials: AuthCredentials): void;
31
+ export declare function saveAuthCredentials(credentials: AuthCredentials): {
32
+ path: string;
33
+ };
37
34
  /**
38
35
  * Delete auth credentials (logout).
39
36
  * Returns true if credentials were deleted, false if they didn't exist.
@@ -43,3 +40,12 @@ export declare function clearAuthCredentials(): boolean;
43
40
  * Get the shed URL from environment or default.
44
41
  */
45
42
  export declare function getShedUrl(): string;
43
+ /**
44
+ * Get shed authentication (access token and URL).
45
+ * Tries auth file first, then SHED_API_KEY environment variable.
46
+ * Returns null if neither is available.
47
+ */
48
+ export declare function getShedAuth(): {
49
+ accessToken: string;
50
+ shedUrl: string;
51
+ } | null;
package/dist/auth.js CHANGED
@@ -9,14 +9,14 @@ const DEFAULT_AUTH_PATH = join(homedir(), ".config", "town", "auth.json");
9
9
  * Get the auth file path.
10
10
  * Uses TOWN_AUTH_PATH env var if set, otherwise defaults to ~/.config/town/auth.json
11
11
  */
12
- export function getAuthFilePath() {
12
+ function getAuthFilePath() {
13
13
  return process.env.TOWN_AUTH_PATH || DEFAULT_AUTH_PATH;
14
14
  }
15
15
  /**
16
16
  * Load auth credentials from disk.
17
17
  * Returns null if not logged in or file is invalid.
18
18
  */
19
- export function loadAuthCredentials() {
19
+ export function loadAuthCredentialsFromDisk() {
20
20
  const authPath = getAuthFilePath();
21
21
  if (!existsSync(authPath)) {
22
22
  return null;
@@ -41,7 +41,7 @@ export function isTokenExpired(credentials) {
41
41
  * Check if user is logged in (has valid credentials file)
42
42
  */
43
43
  export function isLoggedIn() {
44
- return loadAuthCredentials() !== null;
44
+ return loadAuthCredentialsFromDisk() !== null;
45
45
  }
46
46
  /**
47
47
  * Save auth credentials to disk.
@@ -60,6 +60,7 @@ export function saveAuthCredentials(credentials) {
60
60
  catch (error) {
61
61
  throw new Error(`Failed to save auth credentials: ${error instanceof Error ? error.message : String(error)}`);
62
62
  }
63
+ return { path: authPath };
63
64
  }
64
65
  /**
65
66
  * Delete auth credentials (logout).
@@ -84,3 +85,27 @@ export function clearAuthCredentials() {
84
85
  export function getShedUrl() {
85
86
  return process.env.TOWN_SHED_URL || "http://localhost:3000";
86
87
  }
88
+ /**
89
+ * Get shed authentication (access token and URL).
90
+ * Tries auth file first, then SHED_API_KEY environment variable.
91
+ * Returns null if neither is available.
92
+ */
93
+ export function getShedAuth() {
94
+ // Try auth file first
95
+ const credentials = loadAuthCredentialsFromDisk();
96
+ if (credentials) {
97
+ return {
98
+ accessToken: credentials.access_token,
99
+ shedUrl: credentials.shed_url ?? getShedUrl(),
100
+ };
101
+ }
102
+ // Fall back to SHED_API_KEY
103
+ const apiKey = process.env.SHED_API_KEY;
104
+ if (apiKey) {
105
+ return {
106
+ accessToken: apiKey,
107
+ shedUrl: getShedUrl(),
108
+ };
109
+ }
110
+ return null;
111
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@townco/core",
3
3
  "type": "module",
4
- "version": "0.0.46",
4
+ "version": "0.0.48",
5
5
  "description": "core",
6
6
  "license": "UNLICENSED",
7
7
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "typescript": "^5.9.3",
29
- "@townco/tsconfig": "0.1.65"
29
+ "@townco/tsconfig": "0.1.67"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsc",