Skip to content

Commit b25b6ba

Browse files
committed
fix: update dependencies
1 parent b847c3b commit b25b6ba

File tree

13 files changed

+235
-331
lines changed

13 files changed

+235
-331
lines changed

package-lock.json

Lines changed: 108 additions & 244 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
"test": "echo \"Error: no test specified\""
2020
},
2121
"dependencies": {
22-
"@netcentric/cm-notify-core": "^1.0.2",
22+
"@netcentric/cm-notify-core": "^1.0.6",
2323
"dotenv": "16.5.0",
2424
"ejs": "^3.1.10",
2525
"express": "^5.1.0",
26-
"express-session": "^1.18.1",
27-
"google-auth-library": "^9.15.1"
26+
"express-session": "^1.18.1"
2827
},
2928
"devDependencies": {
3029
"@ngrok/ngrok": "^1.4.1"

server/routes/webhook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ router.get('/', (req, res, next) => {
3030
router.post('/', async (req, res, next) => {
3131
let isValidEvent;
3232
try {
33-
isValidEvent = await cmNotify.post(req.body);
33+
isValidEvent = await cmNotify.post(req);
3434
} catch (error) {
3535
console.error('Error posting notification:', error.message);
3636
res.status(400);

setup/adobe/getPipelineData.js renamed to setup/adobe/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { CMUtils } = require('@netcentric/cm-notify-core');
1+
const { CMUtils } = require('../../utils/index');
22

33
const getOrg = (pipelinesJson) => {
44
const pageUrl = pipelinesJson._links.page;

setup/google/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const crypto = require('crypto');
1+
const crypto = require('node:crypto');
22
const express = require('express');
33
const session = require('express-session');
44
const indexRouter = require('./routes/index');

setup/google/authClient.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

setup/google/createHttpServer.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const { createServer } = require('node:http');
2+
3+
/**
4+
* Create an HTTP server.
5+
* @param app
6+
* @param serverPort
7+
*/
8+
function createHttpServer(app, serverPort) {
9+
/**
10+
* Get port from the environment and store in Express.
11+
*/
12+
const port = normalizePort(serverPort);
13+
app.set('port', port);
14+
15+
/**
16+
* Create an HTTP server.
17+
*/
18+
const server = createServer(app);
19+
20+
/**
21+
* Listen on provided port, on all network interfaces.
22+
*/
23+
server.listen(port);
24+
server.on('error', onError);
25+
server.on('listening', onListening);
26+
27+
/**
28+
* Normalize a port into a number, string, or false.
29+
*/
30+
function normalizePort(val) {
31+
const port = parseInt(val, 10);
32+
33+
if (isNaN(port)) {
34+
// named pipe
35+
return val;
36+
}
37+
38+
if (port >= 0) {
39+
// port number
40+
return port;
41+
}
42+
43+
return false;
44+
}
45+
46+
/**
47+
* Event listener for HTTP server "error" event.
48+
*/
49+
function onError(error) {
50+
if (error.syscall !== 'listen') {
51+
throw error;
52+
}
53+
54+
var bind = typeof port === 'string'
55+
? 'Pipe ' + port
56+
: 'Port ' + port;
57+
58+
// handle specific listen errors with friendly messages
59+
switch (error.code) {
60+
case 'EACCES':
61+
console.error(bind + ' requires elevated privileges');
62+
process.exit(1);
63+
break;
64+
case 'EADDRINUSE':
65+
console.error(bind + ' is already in use');
66+
process.exit(1);
67+
break;
68+
default:
69+
throw error;
70+
}
71+
}
72+
73+
/**
74+
* Event listener for HTTP server "listening" event.
75+
*/
76+
function onListening() {
77+
const addr = server.address();
78+
const bind = typeof addr === 'string'
79+
? 'pipe ' + addr
80+
: 'port ' + addr.port;
81+
console.log('Listening on ' + bind);
82+
}
83+
84+
return server;
85+
}
86+
87+
module.exports = { createHttpServer };

setup/google/getAuthUrl.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

setup/google/routes/index.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
1-
const fs = require('node:fs');
21
const express = require('express');
3-
const { CMUtils } = require('@netcentric/cm-notify-core');
4-
const { getCredentials, handleErrorSimple, stopServer } = require('../utils');
2+
const { OAuth2Client } = require('@netcentric/cm-notify-core/core/auth');
3+
const { handleErrorSimple, stopServer } = require('../utils');
54

65
const router = express.Router();
76

87
router.get('/', function(req, res, next) {
9-
const oAuth2Client = require('../authClient');
10-
console.log('GET callback');
11-
const { client_id } = getCredentials();
12-
if (!client_id) {
13-
return handleErrorSimple('No credentials', res, next);
14-
}
8+
const oAuth2Client = new OAuth2Client();
159
// Verify state to prevent CSRF attacks
1610
if (req.query.state !== req.session.state) {
1711
return handleErrorSimple('Invalid state parameter', res, next);
1812
}
13+
1914
if (req.query.error) {
2015
let message = req.query.error;
2116
if (req.query.error === 'interaction_required') {
2217
message = message + '. visit: ' + req.session.authUrl;
2318
}
2419
return handleErrorSimple(message, res, next);
2520
}
21+
2622
if (!req.query.code) {
2723
return handleErrorSimple('No code', res, next);
2824
}
25+
2926
console.log('Code received: ', req.query.code.length);
30-
oAuth2Client.getToken(req.query.code, (err, token) => {
31-
if (err) {
27+
oAuth2Client.saveTokenFromCode(req.query.code)
28+
.then((token) => {
29+
if (!token) {
30+
return handleErrorSimple('Empty token', res, next);
31+
}
32+
console.log('Token received: ', token.expiry_date);
33+
return token;
34+
})
35+
.then(() => {
36+
delete req.session.state;
37+
delete req.session.authUrl;
38+
39+
res.set('Content-Type', 'text/plain');
40+
res.send('Token received. You can close this window.');
41+
})
42+
.catch((err) => {
3243
console.error('Error getting token', err);
3344
return handleErrorSimple('Error getting token', res, next);
34-
}
35-
if (!token) {
36-
return handleErrorSimple('Empty token', res, next);
37-
}
38-
console.log('Token:', token.expiry_date);
39-
delete req.session.state;
40-
delete req.session.authUrl;
41-
const tokenPath = CMUtils.getJsonDataFilePath('google-token.json');
42-
try {
43-
fs.writeFileSync(tokenPath, JSON.stringify(token), 'utf-8');
44-
console.log('Token saved:', tokenPath);
45-
} catch (e) {
46-
console.error('Error saving token', e);
47-
return handleErrorSimple('Error saving token', res, next);
48-
}
49-
res.set('Content-Type', 'text/plain');
50-
res.send('Token received. You can close this window.');
51-
52-
// Shutdown after saving token
53-
setTimeout(() => {
54-
stopServer(req);
55-
}, 1000);
56-
});
45+
})
46+
.finally(() => {;
47+
// Shutdown after saving token
48+
setTimeout(() => {
49+
stopServer(req);
50+
}, 1000);
51+
});
5752
});
5853

5954
module.exports = router;

setup/google/routes/init.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
const { randomBytes} = require('node:crypto');
22
const express = require('express');
3-
const { getAuthUrl } = require('../getAuthUrl');
4-
const { DEFAULT_CONFIG } = require('../../../config');
3+
const { OAuth2Client } = require('@netcentric/cm-notify-core/core/auth');
54

65
const router = express.Router();
76

87
router.get('/', function(req, res, next) {
9-
console.log('GET init');
8+
const oauth2Client = new OAuth2Client();
109
// Generate a secure random state value.
1110
const state = randomBytes(32).toString('hex');
1211
// Store state in the session
1312
req.session.state = state;
14-
const authUrl = getAuthUrl(state, DEFAULT_CONFIG.fromEmail);
13+
const authUrl = oauth2Client.getAuthUrl(state);
1514
req.session.authUrl = authUrl;
1615
res.redirect(authUrl);
1716
});

0 commit comments

Comments
 (0)