jxp 2.9.1 → 2.10.1

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/.env ADDED
@@ -0,0 +1,8 @@
1
+ MONGODB_USER=root
2
+ MONGODB_PASSWORD=password
3
+ MONGODB_DATABASE=jxp
4
+ MONGODB_LOCAL_PORT=7017
5
+ MONGODB_DOCKER_PORT=27017
6
+
7
+ NODE_LOCAL_PORT=4001
8
+ NODE_DOCKER_PORT=4001
package/.env.sample ADDED
@@ -0,0 +1,6 @@
1
+ DB_HOST=localhost
2
+ DB_USER=root
3
+ DB_PASSWORD=password
4
+ DB_NAME=jxp
5
+ DB_PORT=27017
6
+ NODE_DOCKER_PORT=4001
package/Dockerfile ADDED
@@ -0,0 +1,7 @@
1
+ FROM node:17
2
+
3
+ WORKDIR /jxp
4
+ COPY package.json .
5
+ RUN yarn install
6
+ COPY . .
7
+ CMD npm start
package/bin/server.js CHANGED
@@ -195,6 +195,7 @@ Add the parameter `_silence` to supress callbacks. Useful to avoid infinite loop
195
195
  const mongoose = require("mongoose");
196
196
  const JXP = require("../libs/jxp");
197
197
  const config = require("config");
198
+ require("dotenv").config();
198
199
 
199
200
  config.callbacks = {
200
201
  post: function(modelname, item, user) {
@@ -232,15 +233,16 @@ config.pre_hooks = {
232
233
  //DB connection
233
234
  // ES6 promises
234
235
  mongoose.Promise = Promise;
236
+ if (!config.mongo) config.mongo = {};
235
237
  if (!config.mongo.options) config.mongo.options = {};
236
238
  const mongo_options = Object.assign(config.mongo.options, {
237
- promiseLibrary: global.Promise,
238
239
  useNewUrlParser: true,
239
- useCreateIndex: true
240
+ useUnifiedTopology: true
240
241
  });
241
242
 
242
- // mongodb connection
243
- mongoose.connect(config.mongo.connection_string, mongo_options);
243
+ const connection_string = require("../libs/connection_string");
244
+ console.log(`Connecting to ${connection_string}`);
245
+ mongoose.connect(connection_string, mongo_options);
244
246
 
245
247
  const db = mongoose.connection;
246
248
 
@@ -254,7 +256,9 @@ db.once('open', () => {
254
256
 
255
257
  var server = new JXP(config);
256
258
 
257
- server.listen(config.port || 4001, function() {
259
+ let port = process.env.NODE_DOCKER_PORT || process.env.PORT || config.port || 4001;
260
+ if (process.env.NODE_ENV === "test") port = 4005;
261
+ server.listen(port, function() {
258
262
  console.log('%s listening at %s', server.name, server.url);
259
263
  });
260
264
 
@@ -0,0 +1,32 @@
1
+ version: "3.9"
2
+
3
+ services:
4
+ mongodb:
5
+ image: mongo
6
+ restart: always
7
+ environment:
8
+ MONGO_INITDB_ROOT_USERNAME: root
9
+ MONGO_INITDB_ROOT_PASSWORD: password
10
+ ports:
11
+ - $MONGODB_LOCAL_PORT:$MONGODB_DOCKER_PORT
12
+ volumes:
13
+ - db:/data/db
14
+
15
+ jxp:
16
+ depends_on:
17
+ - mongodb
18
+ build: ./
19
+ restart: unless-stopped
20
+ env_file: ./.env
21
+ ports:
22
+ - $NODE_LOCAL_PORT:$NODE_DOCKER_PORT
23
+ environment:
24
+ - DB_HOST=mongodb
25
+ - DB_USER=$MONGODB_USER
26
+ - DB_PASSWORD=$MONGODB_PASSWORD
27
+ - DB_NAME=$MONGODB_DATABASE
28
+ - DB_PORT=$MONGODB_DOCKER_PORT
29
+ stdin_open: true
30
+ tty: true
31
+ volumes:
32
+ db:
@@ -1,5 +1,7 @@
1
1
  # Configuring JXP
2
2
 
3
+ ### NB: The `config` methodology will be deprecated in future versions in favour of dotenv. See the .env.sample for an example.
4
+
3
5
  The config files are stored in `/config` in strict JSON format. (Remember to enclose your keys in inverted commas!) Typically, you'd use `/config/default.json` for a simple configuration, or `/config/development.json` and `/config/production.json` for separating development and production.
4
6
 
5
7
  If you used the `jxp-setup` command for setting everything up, you should have a basic `/config/default.json` file ready to go.
@@ -4,7 +4,7 @@ JXP would typically run as a stand-alone server, although you can include it as
4
4
 
5
5
  ## Requirements
6
6
 
7
- JXP runs on [Node JS](https://nodejs.org/en/). We support Node v10 and above, and recommend Node v12.
7
+ JXP runs on [Node JS](https://nodejs.org/en/). We support Node v10 and above, and recommend Node v16. It has been tested up to Node v17.
8
8
 
9
9
  JXP requires a [Mongo](https://www.mongodb.com/) database server to connect to. You can host your own, or we also support connecting to [MongoDB Atlas](https://www.mongodb.com/cloud/atlas), which has a free tier if you don't want to have Mongo running locally.
10
10
 
@@ -12,6 +12,10 @@ JXP will also take advantage of Memcache if you have it installed, although it's
12
12
 
13
13
  If you want to send out forgotten password links, you'll need an SMTP server you can connect to.
14
14
 
15
+ ## Running on Docker
16
+
17
+ You can run JXP on Docker using Docker Compose. Just run `docker-compose up -d` and it should Just Work (tm).
18
+
15
19
  ## Installing the easy way
16
20
 
17
21
  JXP has a helper that will set up and configure an instance for you.
@@ -0,0 +1,14 @@
1
+ const config = require("config");
2
+ require("dotenv").config();
3
+
4
+ // mongodb connection
5
+ let connection_string = `mongodb://localhost:27017/jxp`;
6
+ if (config.mongo && config.mongo.connection_string) {
7
+ connection_string = config.mongo.connection_string;
8
+ console.warn("`config` to be deprecated in favour of dotenv in future versions");
9
+ }
10
+ if (process.env.DB_HOST) {
11
+ connection_string = `mongodb://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.NODE_ENV === "test" ? "jxp-test" : process.env.DB_NAME}?authSource=admin`
12
+ }
13
+
14
+ module.exports = connection_string;
package/libs/login.js CHANGED
@@ -122,10 +122,7 @@ const oauth_callback = async (req, res, next) => {
122
122
  }
123
123
  user[provider] = data;
124
124
  await user.save();
125
- var apikey = new APIKey();
126
- apikey.user_id = user._id;
127
- apikey.apikey = require('rand-token').generate(16);
128
- await apikey.save();
125
+ const apikey = await security.generateApiKey(user._id)
129
126
  var jwt_token = jwt.sign({ apikey: apikey.apikey, user: user }, req.config.shared_secret, {
130
127
  expiresIn: "1m"
131
128
  });
package/libs/setup.js CHANGED
@@ -3,11 +3,10 @@ const path = require("path");
3
3
  const security = require("./security");
4
4
  const ObjectID = require('mongodb').ObjectID;
5
5
  var User = null;
6
- var connection_string = null;
6
+ const connection_string = require("./connection_string");
7
7
 
8
8
  const init = config => {
9
9
  User = require(path.join(config.model_dir, "user_model"));
10
- connection_string = config.mongo.connection_string;
11
10
  }
12
11
 
13
12
  const checkUserDoesNotExist = async (req, res, next) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jxp",
3
3
  "description:": "An opinionated RESTful API library based on Mongoose and Restify. Make an API by just writing Mongoose models.",
4
- "version": "2.9.1",
4
+ "version": "2.10.1",
5
5
  "private": false,
6
6
  "main": "libs/jxp.js",
7
7
  "scripts": {
@@ -27,37 +27,38 @@
27
27
  "url": "https://github.com/j-norwood-young/jexpress-2/issues"
28
28
  },
29
29
  "dependencies": {
30
- "axios": "^0.21.1",
30
+ "axios": "^0.24.0",
31
31
  "bcryptjs": "^2.4.3",
32
- "commander": "^7.2.0",
32
+ "commander": "^8.3.0",
33
33
  "config": "^3.3.6",
34
- "glob": "7.1.6",
35
- "js-yaml": "4.0.0",
34
+ "dotenv": "^10.0.0",
35
+ "glob": "7.2.0",
36
+ "js-yaml": "4.1.0",
36
37
  "json2csv": "^5.0.6",
37
38
  "jsonwebtoken": "^8.5.1",
38
39
  "jstransformer-markdown-it": "^2.1.0",
39
- "jxp-helper": "^1.3.10",
40
+ "jxp-helper": "^1.3.14",
40
41
  "mkdirp": "^1.0.4",
41
- "mongoose": "5.12.3",
42
+ "mongoose": "6.0.13",
42
43
  "mongoose-friendly": "^0.1.4",
43
44
  "morgan": "^1.10.0",
44
- "nodemailer": "^6.5.0",
45
+ "nodemailer": "^6.7.1",
45
46
  "nodemailer-smtp-transport": "^2.7.4",
46
47
  "path": "^0.12.7",
47
48
  "pug": "^3.0.2",
48
49
  "querystring": "^0.2.1",
49
50
  "rand-token": "^1.0.1",
50
51
  "readline-sync": "^1.4.10",
51
- "restify": "^8.5.1",
52
+ "restify": "^8.6.0",
52
53
  "restify-cors-middleware": "^1.1.1",
53
54
  "traverse": "^0.6.6",
54
- "underscore": "^1.12.1",
55
- "ws": "^7.4.4"
55
+ "underscore": "^1.13.1",
56
+ "ws": "^8.2.3"
56
57
  },
57
58
  "devDependencies": {
58
59
  "chai": "^4.3.4",
59
60
  "chai-http": "^4.3.0",
60
- "mocha": "^8.3.2",
61
+ "mocha": "^9.1.3",
61
62
  "should": "^13.2.3"
62
63
  }
63
64
  }