@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.
- package/.github/CODEOWNERS +1 -9
- package/.github/dependabot.yml +2 -9
- package/.github/workflows/auto-merge.yml +1 -1
- package/.github/workflows/publish-npm.yml +22 -0
- package/{README.MD → README.md} +8 -6
- package/catalog-info.yaml +14 -0
- package/csss.js +120 -119
- package/csss.test.js +6 -6
- package/lib/helpers.js +3 -3
- package/package.json +17 -18
- package/scaffoldTpl/README.MD +1 -3
- package/scaffoldTpl/app.js +32 -31
- package/scaffoldTpl/bin/www +20 -22
- package/scaffoldTpl/lib/ssoMiddleware/index.js +11 -12
- package/scaffoldTpl/package.json +6 -7
- package/scaffoldTpl/public/stylesheets/style.css +1 -1
- package/scaffoldTpl/routes/index.js +3 -3
- package/scaffoldTpl/routes/users.js +3 -3
- package/scaffoldTpl/views/index.html +71 -40
- package/scripts/genDoc.js +21 -21
- package/scaffoldTpl/package-lock.json +0 -1300
package/scaffoldTpl/app.js
CHANGED
|
@@ -1,77 +1,78 @@
|
|
|
1
|
-
let express = require(
|
|
2
|
-
let path = require(
|
|
3
|
-
let favicon = require(
|
|
4
|
-
let logger = require(
|
|
5
|
-
let cookieParser = require(
|
|
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(
|
|
9
|
-
let users = require(
|
|
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(
|
|
17
|
-
|
|
15
|
+
ssoMiddleWare = require("@staffbase/staffbase-plugin-sdk").middleware(
|
|
16
|
+
staffbaseKey,
|
|
17
|
+
pluginID
|
|
18
|
+
);
|
|
18
19
|
|
|
19
20
|
// view engine setup
|
|
20
|
-
app.set(
|
|
21
|
-
app.set(
|
|
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(
|
|
26
|
-
app.use(
|
|
27
|
-
app.use(
|
|
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,
|
|
30
|
+
app.use(express.static(path.join(__dirname, "public")));
|
|
30
31
|
|
|
31
|
-
app.use(
|
|
32
|
-
app.use(
|
|
32
|
+
app.use("/", index);
|
|
33
|
+
app.use("/users", users);
|
|
33
34
|
|
|
34
35
|
// Frontend Handler
|
|
35
|
-
app.use(
|
|
36
|
-
app.get(
|
|
37
|
-
res.render(
|
|
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(
|
|
42
|
+
app.use("/staffbase/sso/backoffice", ssoMiddleWare);
|
|
42
43
|
|
|
43
44
|
// Handle SSO response from server with decoded data
|
|
44
|
-
app.get(
|
|
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(
|
|
48
|
-
res.render(
|
|
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:
|
|
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(
|
|
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(
|
|
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(
|
|
75
|
+
res.render("error");
|
|
75
76
|
});
|
|
76
77
|
|
|
77
78
|
module.exports = app;
|
package/scaffoldTpl/bin/www
CHANGED
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
* Module dependencies.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
var app = require(
|
|
8
|
-
var debug = require(
|
|
9
|
-
var http = require(
|
|
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 ||
|
|
16
|
-
var address = process.env.ADDRESS ||
|
|
17
|
-
app.set(
|
|
18
|
-
app.set(
|
|
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(
|
|
32
|
-
server.on(
|
|
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 !==
|
|
59
|
+
if (error.syscall !== "listen") {
|
|
60
60
|
throw error;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
var bind = typeof port ===
|
|
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
|
|
70
|
-
console.error(bind +
|
|
67
|
+
case "EACCES":
|
|
68
|
+
console.error(bind + " requires elevated privileges");
|
|
71
69
|
process.exit(1);
|
|
72
70
|
break;
|
|
73
|
-
case
|
|
74
|
-
console.error(bind +
|
|
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 ===
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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(
|
|
2
|
-
const helpers = require(
|
|
3
|
-
const
|
|
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(
|
|
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(
|
|
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
|
-
|
|
25
|
-
|
|
23
|
+
let SSOContents = new StaffBaseSSO(formattedSecret, token);
|
|
24
|
+
let tokenData = SSOContents.getTokenData();
|
|
26
25
|
req.sbSSO = tokenData;
|
|
27
|
-
console.log(
|
|
26
|
+
console.log("TokenData:", tokenData);
|
|
28
27
|
return next();
|
|
29
|
-
} catch(
|
|
30
|
-
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.log("Error decoding token:", err);
|
|
31
30
|
return next();
|
|
32
31
|
}
|
|
33
32
|
}
|
package/scaffoldTpl/package.json
CHANGED
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@staffbase/staffbase-plugin-sdk": "^1.3.1",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
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
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
let express = require(
|
|
1
|
+
let express = require("express");
|
|
2
2
|
let router = express.Router();
|
|
3
3
|
|
|
4
4
|
/* GET home page. */
|
|
5
|
-
router.get(
|
|
6
|
-
res.render(
|
|
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(
|
|
1
|
+
let express = require("express");
|
|
2
2
|
let router = express.Router();
|
|
3
3
|
|
|
4
4
|
/* GET users listing. */
|
|
5
|
-
router.get(
|
|
6
|
-
res.send(
|
|
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
|
|
2
|
-
|
|
3
|
-
to get started with your Plugin Application
|
|
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>
|
|
6
|
-
|
|
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>
|
|
9
|
-
|
|
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>
|
|
15
|
-
|
|
16
|
-
|
|
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>
|
|
25
|
-
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
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>
|
|
75
|
+
<p>
|
|
76
|
+
For getting more information about Staffbase SSO, please check out the
|
|
77
|
+
following links:
|
|
78
|
+
</p>
|
|
57
79
|
<ul>
|
|
58
|
-
<li
|
|
59
|
-
<
|
|
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(
|
|
2
|
-
const fs = require(
|
|
3
|
-
const hljs = require(
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const fs = require("fs-extra");
|
|
3
|
+
const hljs = require("highlight.js");
|
|
4
4
|
|
|
5
|
-
const md = require(
|
|
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
|
|
15
|
+
return ""; // use external default escaping
|
|
16
16
|
},
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const input = path.resolve(__dirname,
|
|
20
|
-
const output = path.resolve(__dirname,
|
|
21
|
-
console.log(
|
|
22
|
-
console.log(
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
});
|