@staffbase/create-staffbase-plugin 1.0.6 → 1.0.14

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.
@@ -1,77 +1,78 @@
1
- let express = require('express');
2
- let path = require('path');
3
- let favicon = require('serve-favicon');
4
- let logger = require('morgan');
5
- let cookieParser = require('cookie-parser');
6
- let bodyParser = require('body-parser');
1
+ let express = require("express");
2
+ let path = require("path");
3
+ let favicon = require("serve-favicon");
4
+ let logger = require("morgan");
5
+ let cookieParser = require("cookie-parser");
7
6
 
8
- let index = require('./routes/index');
9
- let users = require('./routes/users');
7
+ let index = require("./routes/index");
8
+ let users = require("./routes/users");
10
9
 
11
10
  let app = express();
12
11
 
13
12
  const staffbaseKey = null;
14
13
  const pluginID = null;
15
14
  let ssoMiddleWare;
16
- ssoMiddleWare = require('@staffbase/staffbase-plugin-sdk').middleware(staffbaseKey, pluginID);
17
-
15
+ ssoMiddleWare = require("@staffbase/staffbase-plugin-sdk").middleware(
16
+ staffbaseKey,
17
+ pluginID
18
+ );
18
19
 
19
20
  // view engine setup
20
- app.set('views', path.join(__dirname, 'views'));
21
- app.set('view engine', 'pug');
21
+ app.set("views", path.join(__dirname, "views"));
22
+ app.set("view engine", "pug");
22
23
 
23
24
  // uncomment after placing your favicon in /public
24
25
  // app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
25
- app.use(logger('dev'));
26
- app.use(bodyParser.json());
27
- app.use(bodyParser.urlencoded({extended: false}));
26
+ app.use(logger("dev"));
27
+ app.use(express.json());
28
+ app.use(express.urlencoded({ extended: false }));
28
29
  app.use(cookieParser());
29
- app.use(express.static(path.join(__dirname, 'public')));
30
+ app.use(express.static(path.join(__dirname, "public")));
30
31
 
31
- app.use('/', index);
32
- app.use('/users', users);
32
+ app.use("/", index);
33
+ app.use("/users", users);
33
34
 
34
35
  // Frontend Handler
35
- app.use('/frontEnd', ssoMiddleWare);
36
- app.get('/frontEnd', function(req, res) {
37
- res.render('plugin', req.sbSSO);
36
+ app.use("/frontEnd", ssoMiddleWare);
37
+ app.get("/frontEnd", function (req, res) {
38
+ res.render("plugin", req.sbSSO);
38
39
  });
39
40
 
40
41
  // Setup SSO Milleware on the endpoint server
41
- app.use('/staffbase/sso/backoffice', ssoMiddleWare);
42
+ app.use("/staffbase/sso/backoffice", ssoMiddleWare);
42
43
 
43
44
  // Handle SSO response from server with decoded data
44
- app.get('/staffbase/sso/backoffice', function(req, res) {
45
+ app.get("/staffbase/sso/backoffice", function (req, res) {
45
46
  // Middleware was able to decode the token
46
47
  if (req.sbSSO) {
47
- console.log('Decoded data on backend(admin):', req.sbSSO);
48
- res.render('plugin', req.sbSSO);
48
+ console.log("Decoded data on backend(admin):", req.sbSSO);
49
+ res.render("plugin", req.sbSSO);
49
50
  return res.end();
50
51
  }
51
52
  res.json({
52
53
  error: {
53
- msg: 'Unable to get token information.',
54
+ msg: "Unable to get token information.",
54
55
  },
55
56
  });
56
57
  return res.end();
57
58
  });
58
59
 
59
60
  // catch 404 and forward to error handler
60
- app.use(function(req, res, next) {
61
- let err = new Error('Not Found');
61
+ app.use(function (req, res, next) {
62
+ let err = new Error("Not Found");
62
63
  err.status = 404;
63
64
  next(err);
64
65
  });
65
66
 
66
67
  // error handler
67
- app.use(function(err, req, res, next) {
68
+ app.use(function (err, req, res, next) {
68
69
  // set locals, only providing error in development
69
70
  res.locals.message = err.message;
70
- res.locals.error = req.app.get('env') === 'development' ? err : {};
71
+ res.locals.error = req.app.get("env") === "development" ? err : {};
71
72
 
72
73
  // render the error page
73
74
  res.status(err.status || 500);
74
- res.render('error');
75
+ res.render("error");
75
76
  });
76
77
 
77
78
  module.exports = app;
@@ -4,18 +4,18 @@
4
4
  * Module dependencies.
5
5
  */
6
6
 
7
- var app = require('../app');
8
- var debug = require('debug')('ssosampleserver:server');
9
- var http = require('http');
7
+ var app = require("../app");
8
+ var debug = require("debug")("ssosampleserver:server");
9
+ var http = require("http");
10
10
 
11
11
  /**
12
12
  * Get port and listen address from environment and store in Express.
13
13
  */
14
14
 
15
- var port = normalizePort(process.env.PORT || '3000');
16
- var address = process.env.ADDRESS || '';
17
- app.set('port', port);
18
- app.set('address', port);
15
+ var port = normalizePort(process.env.PORT || "3000");
16
+ var address = process.env.ADDRESS || "";
17
+ app.set("port", port);
18
+ app.set("address", port);
19
19
 
20
20
  /**
21
21
  * Create HTTP server.
@@ -28,8 +28,8 @@ var server = http.createServer(app);
28
28
  */
29
29
 
30
30
  server.listen(port, address);
31
- server.on('error', onError);
32
- server.on('listening', onListening);
31
+ server.on("error", onError);
32
+ server.on("listening", onListening);
33
33
 
34
34
  /**
35
35
  * Normalize a port into a number, string, or false.
@@ -56,22 +56,20 @@ function normalizePort(val) {
56
56
  */
57
57
 
58
58
  function onError(error) {
59
- if (error.syscall !== 'listen') {
59
+ if (error.syscall !== "listen") {
60
60
  throw error;
61
61
  }
62
62
 
63
- var bind = typeof port === 'string'
64
- ? 'Pipe ' + port
65
- : 'Port ' + port;
63
+ var bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
66
64
 
67
65
  // handle specific listen errors with friendly messages
68
66
  switch (error.code) {
69
- case 'EACCES':
70
- console.error(bind + ' requires elevated privileges');
67
+ case "EACCES":
68
+ console.error(bind + " requires elevated privileges");
71
69
  process.exit(1);
72
70
  break;
73
- case 'EADDRINUSE':
74
- console.error(bind + ' is already in use');
71
+ case "EADDRINUSE":
72
+ console.error(bind + " is already in use");
75
73
  process.exit(1);
76
74
  break;
77
75
  default:
@@ -85,9 +83,9 @@ function onError(error) {
85
83
 
86
84
  function onListening() {
87
85
  var addr = server.address();
88
- var bind = typeof addr === 'string'
89
- ? 'pipe ' + addr
90
- : 'port ' + addr.port;
91
- debug('Listening on ' + bind);
92
- console.log(`Server listening on ${server.address().address}:${server.address().port}`);
86
+ var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
87
+ debug("Listening on " + bind);
88
+ console.log(
89
+ `Server listening on ${server.address().address}:${server.address().port}`
90
+ );
93
91
  }
@@ -1,7 +1,6 @@
1
- const StaffBaseSSO = require('staffbase-sso').sso;
2
- const helpers = require('staffbase-sso').helpers;
3
- const staffbaseSSO1 = require('staffbase-sso');
4
- const TOKEN_QUERY_PARAM = 'jwt';
1
+ const StaffBaseSSO = require("staffbase-sso").sso;
2
+ const helpers = require("staffbase-sso").helpers;
3
+ const TOKEN_QUERY_PARAM = "jwt";
5
4
 
6
5
  function ssoMiddleWare(secret) {
7
6
  secret = secret || process.env.STAFFBASE_SSO_SECRET;
@@ -10,24 +9,24 @@ function ssoMiddleWare(secret) {
10
9
  try {
11
10
  formattedSecret = helpers.transformKeyToFormat(secret);
12
11
  } catch (err) {
13
- console.log('Unable to transform key to right format.', err);
12
+ console.log("Unable to transform key to right format.", err);
14
13
  formattedSecret = null;
15
14
  }
16
- return function(req, res, next) {
15
+ return function (req, res, next) {
17
16
  if (!formattedSecret) {
18
- console.log('Unsupported secret.');
17
+ console.log("Unsupported secret.");
19
18
  return next();
20
19
  }
21
20
  if (req.query[TOKEN_QUERY_PARAM]) {
22
21
  let token = req.query[TOKEN_QUERY_PARAM];
23
22
  try {
24
- let SSOContents = new StaffBaseSSO(formattedSecret, token);
25
- let tokenData = SSOContents.getTokenData();
23
+ let SSOContents = new StaffBaseSSO(formattedSecret, token);
24
+ let tokenData = SSOContents.getTokenData();
26
25
  req.sbSSO = tokenData;
27
- console.log('TokenData:', tokenData);
26
+ console.log("TokenData:", tokenData);
28
27
  return next();
29
- } catch(tokenErr) {
30
- console.log('Error decoding token:', tokenErr);
28
+ } catch (err) {
29
+ console.log("Error decoding token:", err);
31
30
  return next();
32
31
  }
33
32
  }
@@ -7,12 +7,11 @@
7
7
  },
8
8
  "dependencies": {
9
9
  "@staffbase/staffbase-plugin-sdk": "^1.3.1",
10
- "body-parser": "~1.19.2",
11
- "cookie-parser": "~1.4.5",
12
- "debug": "~4.3.1",
13
- "express": "~4.17.3",
14
- "morgan": "~1.10.0",
15
- "pug": ">=3.0.1",
16
- "serve-favicon": "~2.5.0"
10
+ "cookie-parser": "^1.4.7",
11
+ "debug": "^4.4.3",
12
+ "express": "^5.2.1",
13
+ "morgan": "^1.10.0",
14
+ "pug": "^3.0.3",
15
+ "serve-favicon": "^2.5.1"
17
16
  }
18
17
  }
@@ -4,5 +4,5 @@ body {
4
4
  }
5
5
 
6
6
  a {
7
- color: #00B7FF;
7
+ color: #00b7ff;
8
8
  }
@@ -1,9 +1,9 @@
1
- let express = require('express');
1
+ let express = require("express");
2
2
  let router = express.Router();
3
3
 
4
4
  /* GET home page. */
5
- router.get('/', function(req, res, next) {
6
- res.render('index', {title: 'Staffbase SSO Server'});
5
+ router.get("/", function (req, res, next) {
6
+ res.render("index", { title: "Staffbase SSO Server" });
7
7
  });
8
8
 
9
9
  module.exports = router;
@@ -1,9 +1,9 @@
1
- let express = require('express');
1
+ let express = require("express");
2
2
  let router = express.Router();
3
3
 
4
4
  /* GET users listing. */
5
- router.get('/', function(req, res, next) {
6
- res.send('respond with a resource');
5
+ router.get("/", function (req, res, next) {
6
+ res.send("respond with a resource");
7
7
  });
8
8
 
9
9
  module.exports = router;
@@ -1,19 +1,34 @@
1
- <p><img src="https://staffbase.com/wp-content/themes/staffbase-theme/img/logo-blau.svg" alt="Staffbase Logo"></p>
2
- <p>Welcome to your Staffbase SSO plugin server. Please follow the following instructions
3
- to get started with your Plugin Application.</p>
1
+ <p>
2
+ Welcome to your Staffbase SSO plugin server. Please follow the following
3
+ instructions to get started with your Plugin Application.
4
+ </p>
4
5
  <h2>Prerequisites</h2>
5
- <p>In order to get connected with the Staffbase SSO interface, you need a Valid Secret and an Audience ID.</p>
6
- <p>If you are here, you probably have a secret and audience ID registered with Staffbase. If you are not sure about it or you need more information about Staffbase SSO, feel free to contact the Customer Success team at Staffbase.</p>
6
+ <p>
7
+ In order to get connected with the Staffbase SSO interface, you need a Valid
8
+ Secret and an Audience ID.
9
+ </p>
10
+ <p>
11
+ If you are here, you probably have a secret and audience ID registered with
12
+ Staffbase. If you are not sure about it or you need more information about
13
+ Staffbase SSO, feel free to contact the Customer Success team at Staffbase.
14
+ </p>
7
15
  <h2>Configuration</h2>
8
- <p>After the scaffolding is complete, you need to provide some values for configuring your
9
- plugin server. The following values need to be configured.</p>
16
+ <p>
17
+ After the scaffolding is complete, you need to provide some values for
18
+ configuring your plugin server. The following values need to be configured.
19
+ </p>
10
20
  <ul>
11
- <li>Plugin Secret</li>
12
- <li>Plugin Audience</li>
21
+ <li>Plugin Secret</li>
22
+ <li>Plugin Audience</li>
13
23
  </ul>
14
- <p>You can either specify these values in environment variables or directly passing
15
- the values in the <code>app.js</code> file where the middleware is initialized.</p>
16
- <p>To configure values in <code>app.js</code> file, change the following lines:</p>
24
+ <p>
25
+ You can either specify these values in environment variables or directly
26
+ passing the values in the <code>app.js</code> file where the middleware is
27
+ initialized.
28
+ </p>
29
+ <p>
30
+ To configure values in <code>app.js</code> file, change the following lines:
31
+ </p>
17
32
  <p>app.js</p>
18
33
  <pre><code class="language-javascript">12 ...
19
34
  13 ...
@@ -21,40 +36,56 @@ the values in the <code>app.js</code> file where the middleware is initialized.<
21
36
  15 const pluginID = null;
22
37
  16 ...
23
38
  </code></pre>
24
- <p>You can also specify these values using environment variables.
25
- Refer to the table to see which environment variables can be used.</p>
39
+ <p>
40
+ You can also specify these values using environment variables. Refer to the
41
+ table to see which environment variables can be used.
42
+ </p>
26
43
  <table>
27
- <thead>
28
- <tr>
29
- <th style="text-align:left"><em>Value</em></th>
30
- <th style="text-align:center"><em>Environment Variable</em></th>
31
- </tr>
32
- </thead>
33
- <tbody>
34
- <tr>
35
- <td style="text-align:left">Secret</td>
36
- <td style="text-align:center">STAFFBASE_SSO_SECRET</td>
37
- </tr>
38
- <tr>
39
- <td style="text-align:left">Audience</td>
40
- <td style="text-align:center">STAFFBASE_SSO_AUDIENCE</td>
41
- </tr>
42
- <tr>
43
- <td style="text-align:left">Server Port</td>
44
- <td style="text-align:center">PORT</td>
45
- </tr>
46
- </tbody>
44
+ <thead>
45
+ <tr>
46
+ <th style="text-align: left"><em>Value</em></th>
47
+ <th style="text-align: center"><em>Environment Variable</em></th>
48
+ </tr>
49
+ </thead>
50
+ <tbody>
51
+ <tr>
52
+ <td style="text-align: left">Secret</td>
53
+ <td style="text-align: center">STAFFBASE_SSO_SECRET</td>
54
+ </tr>
55
+ <tr>
56
+ <td style="text-align: left">Audience</td>
57
+ <td style="text-align: center">STAFFBASE_SSO_AUDIENCE</td>
58
+ </tr>
59
+ <tr>
60
+ <td style="text-align: left">Server Port</td>
61
+ <td style="text-align: center">PORT</td>
62
+ </tr>
63
+ </tbody>
47
64
  </table>
48
65
  <h2>Running the server</h2>
49
- <p><em>create-staffbase-plugin</em> installs the project dependencies for you.
50
- After configurations is done, the only thing you need to do is navigate to the
51
- folder where your app was generated and start the express server.</p>
66
+ <p>
67
+ <em>create-staffbase-plugin</em> installs the project dependencies for you.
68
+ After configurations is done, the only thing you need to do is navigate to the
69
+ folder where your app was generated and start the express server.
70
+ </p>
52
71
  <pre><code class="language-bash">$ cd [path of generated app]
53
72
  $ npm start
54
73
  </code></pre>
55
74
  <h2>Further Reading</h2>
56
- <p>For getting more information about Staffbase SSO, please check out the following links:</p>
75
+ <p>
76
+ For getting more information about Staffbase SSO, please check out the
77
+ following links:
78
+ </p>
57
79
  <ul>
58
- <li><a href="https://developers.staffbase.com/concepts/customplugin-overview/">Developer Portal: Custom Plugins</a></li>
59
- <li><a href="https://github.com/Staffbase/plugins-sdk-nodejs/blob/master/README.MD">Staffbase Plugins SDK for Node.js</a></li>
80
+ <li>
81
+ <a href="https://developers.staffbase.com/concepts/customplugin-overview/"
82
+ >Developer Portal: Custom Plugins</a
83
+ >
84
+ </li>
85
+ <li>
86
+ <a
87
+ href="https://github.com/Staffbase/plugins-sdk-nodejs/blob/main/README.MD"
88
+ >Staffbase Plugins SDK for Node.js</a
89
+ >
90
+ </li>
60
91
  </ul>
package/scripts/genDoc.js CHANGED
@@ -1,9 +1,9 @@
1
- const path = require('path');
2
- const fs = require('fs-extra');
3
- const hljs = require('highlight.js');
1
+ const path = require("path");
2
+ const fs = require("fs-extra");
3
+ const hljs = require("highlight.js");
4
4
 
5
- const md = require('markdown-it')({
6
- highlight: function(str) {
5
+ const md = require("markdown-it")({
6
+ highlight: function (str) {
7
7
  if (str && hljs.getLanguage(str)) {
8
8
  try {
9
9
  return hljs.highlight(str, true).value;
@@ -12,23 +12,23 @@ const md = require('markdown-it')({
12
12
  }
13
13
  }
14
14
 
15
- return ''; // use external default escaping
15
+ return ""; // use external default escaping
16
16
  },
17
17
  });
18
18
 
19
- const input = path.resolve(__dirname, '../scaffoldTpl/README.MD');
20
- const output = path.resolve(__dirname, '../scaffoldTpl/views/index.html');
21
- console.log('Generating HTML Getting started from README.MD');
22
- console.log('Reading from:', input);
19
+ const input = path.resolve(__dirname, "../scaffoldTpl/README.MD");
20
+ const output = path.resolve(__dirname, "../scaffoldTpl/views/index.html");
21
+ console.log("Generating HTML Getting started from README.MD");
22
+ console.log("Reading from:", input);
23
23
  fs.readFile(input)
24
- .then( (inputStr) => {
25
- // TODO Add better css in the genreated html
26
- const outStr = md.render(inputStr.toString());
27
- return fs.outputFile(output, outStr);
28
- })
29
- .then( (done) => {
30
- console.log('File written to:', output);
31
- })
32
- .catch( (err) => {
33
- console.log(err);
34
- });
24
+ .then((inputStr) => {
25
+ // TODO Add better css in the generated html
26
+ const outStr = md.render(inputStr.toString());
27
+ return fs.outputFile(output, outStr);
28
+ })
29
+ .then((done) => {
30
+ console.log("File written to:", output);
31
+ })
32
+ .catch((err) => {
33
+ console.log(err);
34
+ });