coffeeinabit 0.0.49 → 0.0.52
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/cloud_auth.js +9 -8
- package/helpers/logger.js +43 -0
- package/linkedin_automation.js +191 -190
- package/package.json +1 -1
- package/public/dashboard.html +34 -0
- package/routes/auth.js +10 -9
- package/routes/automation.js +5 -4
- package/routes/users.js +174 -0
- package/server.js +7 -6
- package/tools/get_daily_linkedin_connections.js +4 -4
- package/tools/get_linkedin_updates.js +20 -18
- package/tools/get_profile.js +19 -9
- package/tools/send_connection_request.js +35 -0
package/cloud_auth.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import { logger } from './helpers/logger.js';
|
|
2
3
|
|
|
3
4
|
export class CloudAuth {
|
|
4
5
|
constructor() {
|
|
@@ -30,8 +31,8 @@ export class CloudAuth {
|
|
|
30
31
|
|
|
31
32
|
async exchangeCodeForTokens(code, redirectUri) {
|
|
32
33
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
logger.log('[CloudAuth] Received authorization code:', code.substring(0, 10) + '...');
|
|
35
|
+
logger.log('[CloudAuth] Using redirect_uri:', redirectUri);
|
|
35
36
|
|
|
36
37
|
const response = await axios.get(`https://api.coffeeinabit.com/auth/token?code=${encodeURIComponent(code)}&redirect_url=${encodeURIComponent(redirectUri)}`);
|
|
37
38
|
|
|
@@ -51,7 +52,7 @@ export class CloudAuth {
|
|
|
51
52
|
user: this.extractUserFromToken(id_token)
|
|
52
53
|
};
|
|
53
54
|
} catch (error) {
|
|
54
|
-
|
|
55
|
+
logger.error('[CloudAuth] Token exchange failed:', error.response?.status, error.response?.data);
|
|
55
56
|
return {
|
|
56
57
|
success: false,
|
|
57
58
|
error: error.message
|
|
@@ -96,7 +97,7 @@ export class CloudAuth {
|
|
|
96
97
|
userId: payload.sub
|
|
97
98
|
};
|
|
98
99
|
} catch (error) {
|
|
99
|
-
|
|
100
|
+
logger.error('[CloudAuth] Error extracting user from token:', error.message);
|
|
100
101
|
return null;
|
|
101
102
|
}
|
|
102
103
|
}
|
|
@@ -111,7 +112,7 @@ export class CloudAuth {
|
|
|
111
112
|
const bufferTime = 5 * 60;
|
|
112
113
|
return payload.exp < (Date.now() / 1000) + bufferTime;
|
|
113
114
|
} catch (error) {
|
|
114
|
-
|
|
115
|
+
logger.error('[CloudAuth] Error checking token expiration:', error.message);
|
|
115
116
|
return true;
|
|
116
117
|
}
|
|
117
118
|
}
|
|
@@ -122,7 +123,7 @@ export class CloudAuth {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
if (this.isTokenExpired(session.tokens.idToken)) {
|
|
125
|
-
|
|
126
|
+
logger.log('[CloudAuth] Token expired or expiring soon, attempting refresh...');
|
|
126
127
|
|
|
127
128
|
if (!session.tokens.refreshToken) {
|
|
128
129
|
return { valid: false, error: 'No refresh token available' };
|
|
@@ -144,13 +145,13 @@ export class CloudAuth {
|
|
|
144
145
|
storeTokensInSession(session, tokens, user) {
|
|
145
146
|
session.tokens = tokens;
|
|
146
147
|
session.user = user;
|
|
147
|
-
|
|
148
|
+
logger.log('[CloudAuth] Tokens stored in session for user:', user?.email);
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
clearSession(session) {
|
|
151
152
|
session.tokens = null;
|
|
152
153
|
session.user = null;
|
|
153
|
-
|
|
154
|
+
logger.log('[CloudAuth] Session cleared');
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
isAuthenticated(session) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging utility with timestamp support
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Format timestamp for logging
|
|
7
|
+
* @returns {string} Formatted timestamp string
|
|
8
|
+
*/
|
|
9
|
+
function getTimestamp() {
|
|
10
|
+
const now = new Date();
|
|
11
|
+
return now.toISOString();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Add timestamp to log message
|
|
16
|
+
* @param {...any} args - Log arguments
|
|
17
|
+
* @returns {Array} Arguments with timestamp prefix
|
|
18
|
+
*/
|
|
19
|
+
function formatLogMessage(...args) {
|
|
20
|
+
const timestamp = getTimestamp();
|
|
21
|
+
return [`[${timestamp}]`, ...args];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Logging utilities with timestamps
|
|
26
|
+
*/
|
|
27
|
+
export const logger = {
|
|
28
|
+
log: (...args) => {
|
|
29
|
+
console.log(...formatLogMessage(...args));
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
error: (...args) => {
|
|
33
|
+
console.error(...formatLogMessage(...args));
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
warn: (...args) => {
|
|
37
|
+
console.warn(...formatLogMessage(...args));
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
info: (...args) => {
|
|
41
|
+
console.info(...formatLogMessage(...args));
|
|
42
|
+
}
|
|
43
|
+
};
|