composter-cli 1.0.0 → 1.0.1
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/package.json +9 -2
- package/src/commands/login.js +6 -2
- package/src/utils/request.js +14 -1
- package/src/utils/session.js +17 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "composter-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI tool to manage and sync React components to your personal component vault",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -10,7 +10,14 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
12
|
},
|
|
13
|
-
"keywords": [
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react",
|
|
15
|
+
"components",
|
|
16
|
+
"cli",
|
|
17
|
+
"vault",
|
|
18
|
+
"library",
|
|
19
|
+
"shadcn"
|
|
20
|
+
],
|
|
14
21
|
"author": "binit2-1",
|
|
15
22
|
"license": "MIT",
|
|
16
23
|
"repository": {
|
package/src/commands/login.js
CHANGED
|
@@ -61,11 +61,15 @@ export async function login() {
|
|
|
61
61
|
token = json.token;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// Step 4 — Save session + jwt locally
|
|
64
|
+
// Step 4 — Save session + jwt locally with expiration
|
|
65
|
+
const expiresAt = new Date(Date.now() + (30 * 24 * 60 * 60 * 1000)).toISOString(); // 30 days
|
|
65
66
|
saveSession({
|
|
66
67
|
cookies: cookie,
|
|
67
|
-
jwt: token
|
|
68
|
+
jwt: token,
|
|
69
|
+
createdAt: new Date().toISOString(),
|
|
70
|
+
expiresAt: expiresAt
|
|
68
71
|
});
|
|
69
72
|
|
|
70
73
|
console.log("\nLogged in successfully!");
|
|
74
|
+
console.log(`Session expires: ${expiresAt}`);
|
|
71
75
|
}
|
package/src/utils/request.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fetch from "node-fetch";
|
|
2
|
-
import { loadSession } from "./session.js";
|
|
2
|
+
import { loadSession, clearSession } from "./session.js";
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
4
|
dotenv.config({ silent: true });
|
|
5
5
|
|
|
@@ -7,6 +7,12 @@ const BASE_URL = process.env.BASE_URL || "https://composter.onrender.com/api";
|
|
|
7
7
|
|
|
8
8
|
export async function apiRequest(path, options = {}) {
|
|
9
9
|
const session = loadSession();
|
|
10
|
+
|
|
11
|
+
if (!session) {
|
|
12
|
+
console.error("Not authenticated. Please run 'composter login'");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
const headers = options.headers || {};
|
|
11
17
|
|
|
12
18
|
if (session?.jwt) {
|
|
@@ -18,5 +24,12 @@ export async function apiRequest(path, options = {}) {
|
|
|
18
24
|
headers,
|
|
19
25
|
});
|
|
20
26
|
|
|
27
|
+
// Handle 401 Unauthorized (expired/invalid session)
|
|
28
|
+
if (res.status === 401) {
|
|
29
|
+
console.error("Authentication failed. Please run 'composter login' again");
|
|
30
|
+
clearSession();
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
return res;
|
|
22
35
|
}
|
package/src/utils/session.js
CHANGED
|
@@ -8,7 +8,23 @@ export function saveSession(sessionData) {
|
|
|
8
8
|
|
|
9
9
|
export function loadSession() {
|
|
10
10
|
if (!fs.existsSync(SESSION_PATH)) return null;
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const session = JSON.parse(fs.readFileSync(SESSION_PATH, "utf-8"));
|
|
14
|
+
|
|
15
|
+
// Check if session is expired
|
|
16
|
+
if (session.expiresAt && new Date(session.expiresAt) < new Date()) {
|
|
17
|
+
console.log("Session expired. Please run 'composter login' again.");
|
|
18
|
+
clearSession();
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return session;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error("Invalid session file. Please run 'composter login' again.");
|
|
25
|
+
clearSession();
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
12
28
|
}
|
|
13
29
|
|
|
14
30
|
export function clearSession() {
|