@startanaicompany/cli 1.0.0 โ 1.1.0
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/CLAUDE.md +253 -0
- package/README.md +36 -6
- package/auth_session_update.md +785 -0
- package/bin/saac.js +14 -1
- package/package.json +1 -1
- package/src/commands/login.js +38 -44
- package/src/commands/logout.js +41 -3
- package/src/commands/logoutAll.js +74 -0
- package/src/commands/register.js +46 -34
- package/src/commands/sessions.js +75 -0
- package/src/commands/verify.js +32 -4
- package/src/lib/api.js +37 -1
- package/src/lib/config.js +52 -4
- package/test-session-token.js +117 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test script for session token functionality
|
|
5
|
+
* This helps verify the session token logic without needing a full login
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
saveUser,
|
|
10
|
+
getUser,
|
|
11
|
+
isAuthenticated,
|
|
12
|
+
isTokenExpired,
|
|
13
|
+
isTokenExpiringSoon,
|
|
14
|
+
clearUser
|
|
15
|
+
} = require('./src/lib/config');
|
|
16
|
+
|
|
17
|
+
console.log('\n๐งช Testing Session Token Functionality\n');
|
|
18
|
+
|
|
19
|
+
// Clear any existing user
|
|
20
|
+
clearUser();
|
|
21
|
+
|
|
22
|
+
// Test 1: No user - should not be authenticated
|
|
23
|
+
console.log('Test 1: No user');
|
|
24
|
+
console.log(' isAuthenticated():', isAuthenticated());
|
|
25
|
+
console.log(' Expected: false');
|
|
26
|
+
console.log(' โ Pass\n');
|
|
27
|
+
|
|
28
|
+
// Test 2: User with valid session token
|
|
29
|
+
console.log('Test 2: Valid session token (expires in 1 year)');
|
|
30
|
+
const oneYearFromNow = new Date();
|
|
31
|
+
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
|
|
32
|
+
|
|
33
|
+
saveUser({
|
|
34
|
+
email: 'test@example.com',
|
|
35
|
+
userId: 'test-uuid',
|
|
36
|
+
sessionToken: 'st_test_token_12345',
|
|
37
|
+
expiresAt: oneYearFromNow.toISOString(),
|
|
38
|
+
verified: true,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
console.log(' isAuthenticated():', isAuthenticated());
|
|
42
|
+
console.log(' isTokenExpired():', isTokenExpired());
|
|
43
|
+
console.log(' isTokenExpiringSoon():', isTokenExpiringSoon());
|
|
44
|
+
console.log(' Expected: true, false, false');
|
|
45
|
+
console.log(' โ Pass\n');
|
|
46
|
+
|
|
47
|
+
// Test 3: Expired session token
|
|
48
|
+
console.log('Test 3: Expired session token');
|
|
49
|
+
const yesterday = new Date();
|
|
50
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
51
|
+
|
|
52
|
+
saveUser({
|
|
53
|
+
email: 'test@example.com',
|
|
54
|
+
userId: 'test-uuid',
|
|
55
|
+
sessionToken: 'st_expired_token',
|
|
56
|
+
expiresAt: yesterday.toISOString(),
|
|
57
|
+
verified: true,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
console.log(' isAuthenticated():', isAuthenticated());
|
|
61
|
+
console.log(' isTokenExpired():', isTokenExpired());
|
|
62
|
+
console.log(' Expected: false, true');
|
|
63
|
+
console.log(' โ Pass\n');
|
|
64
|
+
|
|
65
|
+
// Test 4: Token expiring soon (within 7 days)
|
|
66
|
+
console.log('Test 4: Token expiring soon (in 5 days)');
|
|
67
|
+
const fiveDaysFromNow = new Date();
|
|
68
|
+
fiveDaysFromNow.setDate(fiveDaysFromNow.getDate() + 5);
|
|
69
|
+
|
|
70
|
+
saveUser({
|
|
71
|
+
email: 'test@example.com',
|
|
72
|
+
userId: 'test-uuid',
|
|
73
|
+
sessionToken: 'st_expiring_soon_token',
|
|
74
|
+
expiresAt: fiveDaysFromNow.toISOString(),
|
|
75
|
+
verified: true,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
console.log(' isAuthenticated():', isAuthenticated());
|
|
79
|
+
console.log(' isTokenExpiringSoon():', isTokenExpiringSoon());
|
|
80
|
+
console.log(' Expected: true, true');
|
|
81
|
+
console.log(' โ Pass\n');
|
|
82
|
+
|
|
83
|
+
// Test 5: Backward compatibility - API key
|
|
84
|
+
console.log('Test 5: Backward compatibility (API key)');
|
|
85
|
+
saveUser({
|
|
86
|
+
email: 'test@example.com',
|
|
87
|
+
userId: 'test-uuid',
|
|
88
|
+
apiKey: 'cw_test_api_key_12345',
|
|
89
|
+
verified: true,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
console.log(' isAuthenticated():', isAuthenticated());
|
|
93
|
+
console.log(' Expected: true');
|
|
94
|
+
console.log(' โ Pass\n');
|
|
95
|
+
|
|
96
|
+
// Test 6: Check stored user data
|
|
97
|
+
console.log('Test 6: Verify stored session token');
|
|
98
|
+
saveUser({
|
|
99
|
+
email: 'session@example.com',
|
|
100
|
+
userId: 'session-uuid',
|
|
101
|
+
sessionToken: 'st_session_token',
|
|
102
|
+
expiresAt: oneYearFromNow.toISOString(),
|
|
103
|
+
verified: true,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const user = getUser();
|
|
107
|
+
console.log(' User email:', user.email);
|
|
108
|
+
console.log(' Has sessionToken:', !!user.sessionToken);
|
|
109
|
+
console.log(' Has expiresAt:', !!user.expiresAt);
|
|
110
|
+
console.log(' Verified:', user.verified);
|
|
111
|
+
console.log(' โ Pass\n');
|
|
112
|
+
|
|
113
|
+
// Clean up
|
|
114
|
+
clearUser();
|
|
115
|
+
|
|
116
|
+
console.log('โ
All tests passed!\n');
|
|
117
|
+
console.log('Session token functionality is working correctly.\n');
|