jxp 2.16.0 → 4.0.0
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.sample +31 -6
- package/README.md +27 -13
- package/dist/bin/init_db.d.ts +3 -0
- package/dist/bin/init_db.d.ts.map +1 -0
- package/dist/bin/init_db.js +48 -0
- package/dist/bin/init_db.js.map +1 -0
- package/dist/bin/server.d.ts +4 -0
- package/dist/bin/server.d.ts.map +1 -0
- package/dist/bin/server.js +132 -0
- package/dist/bin/server.js.map +1 -0
- package/dist/bin/setup.d.ts +3 -0
- package/dist/bin/setup.d.ts.map +1 -0
- package/dist/bin/setup.js +185 -0
- package/dist/bin/setup.js.map +1 -0
- package/dist/globals.d.ts +14 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +3 -0
- package/dist/globals.js.map +1 -0
- package/dist/libs/aggregate_guard.d.ts +5 -0
- package/dist/libs/aggregate_guard.d.ts.map +1 -0
- package/dist/libs/aggregate_guard.js +58 -0
- package/dist/libs/aggregate_guard.js.map +1 -0
- package/dist/libs/bulkwrite_guard.d.ts +5 -0
- package/dist/libs/bulkwrite_guard.d.ts.map +1 -0
- package/dist/libs/bulkwrite_guard.js +44 -0
- package/dist/libs/bulkwrite_guard.js.map +1 -0
- package/dist/libs/cache.d.ts +2 -0
- package/dist/libs/cache.d.ts.map +1 -0
- package/dist/libs/cache.js +94 -0
- package/dist/libs/cache.js.map +1 -0
- package/dist/libs/call_guard.d.ts +3 -0
- package/dist/libs/call_guard.d.ts.map +1 -0
- package/dist/libs/call_guard.js +17 -0
- package/dist/libs/call_guard.js.map +1 -0
- package/dist/libs/connection_string.d.ts +3 -0
- package/dist/libs/connection_string.d.ts.map +1 -0
- package/dist/libs/connection_string.js +4 -0
- package/dist/libs/connection_string.js.map +1 -0
- package/dist/libs/datamunging.d.ts +2 -0
- package/dist/libs/datamunging.d.ts.map +1 -0
- package/dist/libs/datamunging.js +320 -0
- package/dist/libs/datamunging.js.map +1 -0
- package/dist/libs/docs.d.ts +2 -0
- package/dist/libs/docs.d.ts.map +1 -0
- package/dist/libs/docs.js +307 -0
- package/dist/libs/docs.js.map +1 -0
- package/dist/libs/groups.d.ts +2 -0
- package/dist/libs/groups.d.ts.map +1 -0
- package/dist/libs/groups.js +136 -0
- package/dist/libs/groups.js.map +1 -0
- package/dist/libs/jxp.d.ts +4 -0
- package/dist/libs/jxp.d.ts.map +1 -0
- package/dist/libs/jxp.js +1157 -0
- package/dist/libs/jxp.js.map +1 -0
- package/dist/libs/link_index.d.ts +14 -0
- package/dist/libs/link_index.d.ts.map +1 -0
- package/dist/libs/link_index.js +37 -0
- package/dist/libs/link_index.js.map +1 -0
- package/dist/libs/load-config.d.ts +16 -0
- package/dist/libs/load-config.d.ts.map +1 -0
- package/dist/libs/load-config.js +155 -0
- package/dist/libs/load-config.js.map +1 -0
- package/dist/libs/login.d.ts +2 -0
- package/dist/libs/login.d.ts.map +1 -0
- package/dist/libs/login.js +244 -0
- package/dist/libs/login.js.map +1 -0
- package/dist/libs/modeldir.d.ts +5 -0
- package/dist/libs/modeldir.d.ts.map +1 -0
- package/dist/libs/modeldir.js +15 -0
- package/dist/libs/modeldir.js.map +1 -0
- package/dist/libs/query_limits.d.ts +2 -0
- package/dist/libs/query_limits.d.ts.map +1 -0
- package/dist/libs/query_limits.js +84 -0
- package/dist/libs/query_limits.js.map +1 -0
- package/dist/libs/query_manipulation.d.ts +3 -0
- package/dist/libs/query_manipulation.d.ts.map +1 -0
- package/{libs → dist/libs}/query_manipulation.js +22 -21
- package/dist/libs/query_manipulation.js.map +1 -0
- package/dist/libs/query_sanitize.d.ts +5 -0
- package/dist/libs/query_sanitize.d.ts.map +1 -0
- package/dist/libs/query_sanitize.js +109 -0
- package/dist/libs/query_sanitize.js.map +1 -0
- package/dist/libs/response_sanitize.d.ts +7 -0
- package/dist/libs/response_sanitize.d.ts.map +1 -0
- package/dist/libs/response_sanitize.js +57 -0
- package/dist/libs/response_sanitize.js.map +1 -0
- package/dist/libs/safe_error.d.ts +3 -0
- package/dist/libs/safe_error.d.ts.map +1 -0
- package/dist/libs/safe_error.js +14 -0
- package/dist/libs/safe_error.js.map +1 -0
- package/dist/libs/schema.d.ts +14 -0
- package/dist/libs/schema.d.ts.map +1 -0
- package/dist/libs/schema.js +98 -0
- package/dist/libs/schema.js.map +1 -0
- package/dist/libs/schema_description.d.ts +3 -0
- package/dist/libs/schema_description.d.ts.map +1 -0
- package/{libs → dist/libs}/schema_description.js +12 -21
- package/dist/libs/schema_description.js.map +1 -0
- package/dist/libs/security.d.ts +2 -0
- package/dist/libs/security.d.ts.map +1 -0
- package/dist/libs/security.js +428 -0
- package/dist/libs/security.js.map +1 -0
- package/dist/libs/setup.d.ts +2 -0
- package/dist/libs/setup.d.ts.map +1 -0
- package/dist/libs/setup.js +87 -0
- package/dist/libs/setup.js.map +1 -0
- package/dist/libs/startup-deprecations.d.ts +2 -0
- package/dist/libs/startup-deprecations.d.ts.map +1 -0
- package/dist/libs/startup-deprecations.js +21 -0
- package/dist/libs/startup-deprecations.js.map +1 -0
- package/dist/libs/startup.d.ts +16 -0
- package/dist/libs/startup.d.ts.map +1 -0
- package/dist/libs/startup.js +63 -0
- package/dist/libs/startup.js.map +1 -0
- package/dist/libs/ws.d.ts +2 -0
- package/dist/libs/ws.d.ts.map +1 -0
- package/{libs → dist/libs}/ws.js +114 -73
- package/dist/libs/ws.js.map +1 -0
- package/dist/models/apikey_model.d.ts +10 -0
- package/dist/models/apikey_model.d.ts.map +1 -0
- package/dist/models/apikey_model.js +14 -0
- package/dist/models/apikey_model.js.map +1 -0
- package/dist/models/link_model.d.ts +9 -0
- package/dist/models/link_model.d.ts.map +1 -0
- package/dist/models/link_model.js +20 -0
- package/dist/models/link_model.js.map +1 -0
- package/dist/models/refreshtoken_model.d.ts +11 -0
- package/dist/models/refreshtoken_model.d.ts.map +1 -0
- package/dist/models/refreshtoken_model.js +22 -0
- package/dist/models/refreshtoken_model.js.map +1 -0
- package/dist/models/test_model.d.ts +24 -0
- package/dist/models/test_model.d.ts.map +1 -0
- package/dist/models/test_model.js +44 -0
- package/dist/models/test_model.js.map +1 -0
- package/dist/models/token_model.d.ts +14 -0
- package/dist/models/token_model.d.ts.map +1 -0
- package/dist/models/token_model.js +25 -0
- package/dist/models/token_model.js.map +1 -0
- package/dist/models/user_model.d.ts +15 -0
- package/dist/models/user_model.d.ts.map +1 -0
- package/dist/models/user_model.js +38 -0
- package/dist/models/user_model.js.map +1 -0
- package/dist/models/usergroups_model.d.ts +9 -0
- package/dist/models/usergroups_model.d.ts.map +1 -0
- package/dist/models/usergroups_model.js +18 -0
- package/dist/models/usergroups_model.js.map +1 -0
- package/dist/types/jxp-config.d.ts +134 -0
- package/dist/types/jxp-config.d.ts.map +1 -0
- package/dist/types/jxp-config.js +3 -0
- package/dist/types/jxp-config.js.map +1 -0
- package/dist/types/schema-fields.d.ts +43 -0
- package/dist/types/schema-fields.d.ts.map +1 -0
- package/dist/types/schema-fields.js +3 -0
- package/dist/types/schema-fields.js.map +1 -0
- package/docs/aggregations.md +40 -21
- package/docs/api.md +55 -15
- package/docs/authentication.md +60 -37
- package/docs/bulk_writes.md +11 -8
- package/docs/caching.md +28 -11
- package/docs/changelog.md +237 -31
- package/docs/configuration.md +99 -118
- package/docs/hooks.md +12 -8
- package/docs/index.md +17 -17
- package/docs/installation.md +23 -18
- package/docs/permissions.md +33 -19
- package/docs/queries.md +9 -5
- package/docs/schemas.md +21 -10
- package/docs/special.md +4 -4
- package/docs/typescript.md +86 -0
- package/docs/websocket.md +99 -1
- package/mkdocs.yml +1 -0
- package/package.json +121 -69
- package/templates/api.pug +32 -0
- package/templates/app-server.js +43 -0
- package/templates/app.env.sample +8 -0
- package/templates/assets/api-console.js +133 -0
- package/templates/assets/docs.css +227 -0
- package/templates/index.pug +62 -2
- package/templates/layout.pug +17 -11
- package/templates/md.pug +1 -1
- package/templates/model.pug +117 -68
- package/templates/navbar.pug +14 -21
- package/templates/sidebar.pug +30 -0
- package/.env +0 -9
- package/.eslintrc.json +0 -20
- package/.jshintrc +0 -4
- package/.vscode/launch.json +0 -29
- package/.vscode/settings.json +0 -3
- package/Dockerfile +0 -7
- package/bin/init_db.js +0 -54
- package/bin/server.js +0 -84
- package/bin/setup.js +0 -190
- package/config_sample.json +0 -10
- package/docker-compose.yml +0 -32
- package/libs/cache.js +0 -92
- package/libs/connection_string.js +0 -24
- package/libs/datamunging.js +0 -335
- package/libs/docs.js +0 -162
- package/libs/groups.js +0 -133
- package/libs/jxp.js +0 -1208
- package/libs/login.js +0 -218
- package/libs/modeldir.js +0 -14
- package/libs/schema.js +0 -99
- package/libs/security.js +0 -410
- package/libs/setup.js +0 -90
- package/models/apikey_model.js +0 -10
- package/models/link_model.js +0 -17
- package/models/refreshtoken_model.js +0 -20
- package/models/test_model.js +0 -50
- package/models/token_model.js +0 -23
- package/models/user_model.js +0 -38
- package/models/usergroups_model.js +0 -15
- package/setup.sh +0 -3
- package/test/.eslintrc.json +0 -13
- package/test/init.js +0 -92
- package/test/setup.test.js +0 -62
- package/test/test.js +0 -1527
- package/test/wstest.js.old +0 -124
package/bin/setup.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
const mkdirp = require("mkdirp");
|
|
3
|
-
const program = require("commander");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const readline = require('readline-sync');
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
const crypto = require("crypto");
|
|
8
|
-
const execSync = require('child_process').execSync;
|
|
9
|
-
const mongoose = require("mongoose");
|
|
10
|
-
|
|
11
|
-
const security = require("../libs/security");
|
|
12
|
-
global.JXPSchema = require("../libs/schema");
|
|
13
|
-
|
|
14
|
-
const User = require("../models/user_model");
|
|
15
|
-
|
|
16
|
-
const pkg = require('../package.json');
|
|
17
|
-
|
|
18
|
-
const version = pkg.version;
|
|
19
|
-
|
|
20
|
-
program
|
|
21
|
-
.version(version)
|
|
22
|
-
.usage('[options] [dir]')
|
|
23
|
-
.option('-v, --version', 'JXP version')
|
|
24
|
-
.parse(process.argv);
|
|
25
|
-
|
|
26
|
-
async function main() {
|
|
27
|
-
try {
|
|
28
|
-
const models = ["apikey", "test", "token", "user", "usergroups", "link", "refreshtoken"];
|
|
29
|
-
const destination_path = program.args.shift() || '.';
|
|
30
|
-
// Get some defaults
|
|
31
|
-
let default_author_name = "Me";
|
|
32
|
-
let default_author_email = "me@example.com";
|
|
33
|
-
let default_app_description = "A JXP installation";
|
|
34
|
-
let default_license = "MIT";
|
|
35
|
-
let default_version = "0.0.1";
|
|
36
|
-
try {
|
|
37
|
-
default_author_name = execSync('git config --global user.name', { encoding: 'utf-8' }).trim();
|
|
38
|
-
default_author_email = execSync('git config --global user.email', { encoding: 'utf-8' }).trim();
|
|
39
|
-
} catch(err) {
|
|
40
|
-
// Nothing to see here
|
|
41
|
-
}
|
|
42
|
-
let default_app_author = `${default_author_name} <${default_author_email}>`;
|
|
43
|
-
// Ask the basics
|
|
44
|
-
let default_app_name = path.basename(path.resolve(destination_path));
|
|
45
|
-
const app_name = readline.question(`App name (${default_app_name}): `, { defaultInput: default_app_name });
|
|
46
|
-
const app_description = readline.question(`App description (${default_app_description}): `, { defaultInput: default_app_description });
|
|
47
|
-
const app_license = readline.question(`Licence (${default_license}): `, { defaultInput: default_license });
|
|
48
|
-
const app_author = readline.question(`Author (${default_app_author}): `, { defaultInput: default_app_author });
|
|
49
|
-
const app_version = readline.question(`Version (${default_version}): `, { defaultInput: default_version });
|
|
50
|
-
var opts = {};
|
|
51
|
-
// Config setup
|
|
52
|
-
// opts.email = readline.question("Admin email address: ");
|
|
53
|
-
// opts.password = readline.question("Admin password: ", { hideEchoBack: true });
|
|
54
|
-
opts.port = readline.question("Port (2001): ", { defaultInput: "2001" });
|
|
55
|
-
opts.url = readline.question("URL (http://localhost:" + opts.port + "): ", { defaultInput: "http://localhost:" + opts.port });
|
|
56
|
-
const default_connection_string = `mongodb://localhost/${ app_name }?retryWrites=true&w=majority`;
|
|
57
|
-
opts.connection_string = readline.question(`Mongo connection string (${default_connection_string}): `, { defaultInput: default_connection_string });
|
|
58
|
-
const email = readline.question(`Admin user email (${default_author_email}): `);
|
|
59
|
-
const name = readline.question(`Admin user name (${default_author_name}): `, { defaultInput: "Admin" });
|
|
60
|
-
const random_password = crypto.randomBytes(12).toString('base64');
|
|
61
|
-
const password = readline.question(`Admin user password (${random_password}): `, { hideEchoBack: true, defaultInput: random_password });
|
|
62
|
-
opts.shared_secret = crypto.randomBytes(20).toString('hex');
|
|
63
|
-
const package_data = {
|
|
64
|
-
"name": app_name,
|
|
65
|
-
"version": app_version,
|
|
66
|
-
"description": app_description,
|
|
67
|
-
"main": "bin/server.js",
|
|
68
|
-
"scripts": {
|
|
69
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
70
|
-
"start": "node bin/server.js"
|
|
71
|
-
},
|
|
72
|
-
"dependencies": {
|
|
73
|
-
"jxp": "^2.12.3"
|
|
74
|
-
},
|
|
75
|
-
"author": app_author,
|
|
76
|
-
"license": app_license
|
|
77
|
-
};
|
|
78
|
-
await mkdirp(destination_path); // Ensure the dir exists
|
|
79
|
-
write(path.join(destination_path, "package.json"), JSON.stringify(package_data, null, "\t"));
|
|
80
|
-
await mkdir(path.join(destination_path, "bin"));
|
|
81
|
-
await mkdir(path.join(destination_path, "models"));
|
|
82
|
-
await mkdir(path.join(destination_path, "config"));
|
|
83
|
-
await mkdir(path.join(destination_path, "logs"));
|
|
84
|
-
await mkdir(path.join(destination_path, "libs"));
|
|
85
|
-
await cp_replace("../config_sample.json", path.join(destination_path, "config/default.json"), opts, "{", "}");
|
|
86
|
-
await cp_replace("./server.js", path.join(destination_path, "bin/server.js"), { "../libs/jxp": "jxp/libs/jxp", "../libs/connection_string": "jxp/libs/connection_string" });
|
|
87
|
-
for (let model of models) {
|
|
88
|
-
await cp("../models/" + model + "_model.js", path.join(destination_path, "models/" + model + "_model.js"));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
console.log();
|
|
92
|
-
console.log("Installing dependencies...")
|
|
93
|
-
console.log();
|
|
94
|
-
|
|
95
|
-
execSync(`cd ${destination_path} && npm install`);
|
|
96
|
-
|
|
97
|
-
console.log();
|
|
98
|
-
console.log("Setting up your admin user...")
|
|
99
|
-
console.log();
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
mongoose.connect(opts.connection_string, function (err) {
|
|
103
|
-
if (err) {
|
|
104
|
-
throw(err);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}, {
|
|
108
|
-
db: {
|
|
109
|
-
safe: true
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
} catch(err) {
|
|
113
|
-
console.log("WARNING: We had a problem talking to the database")
|
|
114
|
-
console.error(err);
|
|
115
|
-
return process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
var user = new User();
|
|
118
|
-
user.email = email;
|
|
119
|
-
user.password = security.encPassword(password);
|
|
120
|
-
user.name = name;
|
|
121
|
-
user.admin = true;
|
|
122
|
-
user.save((err) => {
|
|
123
|
-
if (err) {
|
|
124
|
-
console.log("Error saving user");
|
|
125
|
-
console.error(err.message);
|
|
126
|
-
return process.exit(1);
|
|
127
|
-
} else {
|
|
128
|
-
console.log("Created admin user", name, "<" + email + ">");
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
process.chdir(destination_path);
|
|
132
|
-
console.log("Congratulations! Your JXP server is ready to go. Happy API'ing...");
|
|
133
|
-
console.log("Next steps:");
|
|
134
|
-
console.log("0. Change to your directory");
|
|
135
|
-
console.log(` cd ${ destination_path }`);
|
|
136
|
-
console.log("1. Start your server");
|
|
137
|
-
console.log(" npm start");
|
|
138
|
-
console.log("2. Connect to your server");
|
|
139
|
-
console.log(` ${opts.url}`);
|
|
140
|
-
return process.exit(0);
|
|
141
|
-
} catch(err) {
|
|
142
|
-
console.log("Error:", err.message);
|
|
143
|
-
return process.exit(1);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Copy from to replacing text as we go
|
|
149
|
-
*
|
|
150
|
-
*/
|
|
151
|
-
function cp_replace(from, to, opts, startEnclosure = "", endEnclosure = "") {
|
|
152
|
-
startEnclosure = startEnclosure || "";
|
|
153
|
-
endEnclosure = endEnclosure || "";
|
|
154
|
-
from = path.join(__dirname, from);
|
|
155
|
-
var s = fs.readFileSync(from, "utf-8");
|
|
156
|
-
for(var i in opts) {
|
|
157
|
-
console.log(startEnclosure + i + endEnclosure, opts[i]);
|
|
158
|
-
s = s.replace(startEnclosure + i + endEnclosure, opts[i]);
|
|
159
|
-
}
|
|
160
|
-
write(to, s);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Copy from to
|
|
165
|
-
*
|
|
166
|
-
* @param {String} from
|
|
167
|
-
* @param {String} to
|
|
168
|
-
*/
|
|
169
|
-
function cp(from, to) {
|
|
170
|
-
from = path.join(__dirname, from);
|
|
171
|
-
write(to, fs.readFileSync(from, 'utf-8'));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function write(path, str, mode) {
|
|
175
|
-
fs.writeFileSync(path, str, { mode });
|
|
176
|
-
console.log(' \x1b[36mcreate\x1b[0m : ' + path);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Mkdir -p.
|
|
181
|
-
*
|
|
182
|
-
* @param {String} path
|
|
183
|
-
* @return {Promise}
|
|
184
|
-
*/
|
|
185
|
-
|
|
186
|
-
function mkdir(path) {
|
|
187
|
-
return mkdirp(path, 0o755);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
main();
|
package/config_sample.json
DELETED
package/docker-compose.yml
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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:
|
package/libs/cache.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const NodeCache = require('node-cache');
|
|
2
|
-
let cache;
|
|
3
|
-
|
|
4
|
-
const init = (config) => {
|
|
5
|
-
if (!config.cache || !config.cache.enabled) return;
|
|
6
|
-
cache = new NodeCache({ stdTTL: config.cache.ttl || 5 * 60 });
|
|
7
|
-
if (config.cache.debug) {
|
|
8
|
-
cache.on('expired', (key) => {
|
|
9
|
-
console.log('cache expired', key)
|
|
10
|
-
})
|
|
11
|
-
cache.on('flush', () => {
|
|
12
|
-
console.log('cache flush')
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const generateKey = (req, res) => {
|
|
18
|
-
if (res.jxp_cache_key) return res.jxp_cache_key;
|
|
19
|
-
let key = `${req.modelname}/`;
|
|
20
|
-
if (req.params.item_id) {
|
|
21
|
-
key += `${req.params.item_id}`
|
|
22
|
-
}
|
|
23
|
-
if (req.query) {
|
|
24
|
-
key += `?${JSON.stringify(req.query)}`
|
|
25
|
-
}
|
|
26
|
-
res.jxp_cache_key = key;
|
|
27
|
-
return key;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const set = async (req, res) => {
|
|
31
|
-
if (!cache) return;
|
|
32
|
-
const key = generateKey(req, res)
|
|
33
|
-
cache.set(key, res.result)
|
|
34
|
-
if (!req.config.cache.debug) {
|
|
35
|
-
console.log('cache set', key)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const get = (req, res, next) => {
|
|
40
|
-
if (!cache) return next();
|
|
41
|
-
const key = generateKey(req, res)
|
|
42
|
-
res.header('jxp-cache-key', key);
|
|
43
|
-
const cached = cache.get(key)
|
|
44
|
-
if (cached) {
|
|
45
|
-
if (!req.config.cache.debug) {
|
|
46
|
-
console.log('cache hit', key)
|
|
47
|
-
}
|
|
48
|
-
res.header('jxp-cache', 'hit')
|
|
49
|
-
res.result = cached
|
|
50
|
-
res.send(res.result);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (!req.config.cache.debug) {
|
|
54
|
-
console.log('cache miss', key)
|
|
55
|
-
}
|
|
56
|
-
res.header('jxp-cache', 'miss')
|
|
57
|
-
next()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const clear = async (req) => {
|
|
61
|
-
if (!cache) return;
|
|
62
|
-
const keys = cache.keys()
|
|
63
|
-
keys.forEach(key => {
|
|
64
|
-
if (key.startsWith(`${req.modelname}/`)) {
|
|
65
|
-
if (!req.config.cache.debug) {
|
|
66
|
-
console.log('cache del', key)
|
|
67
|
-
}
|
|
68
|
-
cache.del(key)
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const clearAll = async () => {
|
|
74
|
-
cache.flushAll()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const stats = async (req, res) => {
|
|
78
|
-
if (!cache) {
|
|
79
|
-
res.result = { cache_enabled: false }
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
res.result = cache.getStats()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
module.exports = {
|
|
86
|
-
init,
|
|
87
|
-
set,
|
|
88
|
-
get,
|
|
89
|
-
clear,
|
|
90
|
-
clearAll,
|
|
91
|
-
stats,
|
|
92
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const config = require("config");
|
|
2
|
-
require("dotenv").config();
|
|
3
|
-
|
|
4
|
-
// mongodb connection
|
|
5
|
-
const {
|
|
6
|
-
MONGODB_USER,
|
|
7
|
-
MONGODB_PASSWORD,
|
|
8
|
-
MONGODB_HOST,
|
|
9
|
-
MONGODB_PORT,
|
|
10
|
-
MONGODB_NAME,
|
|
11
|
-
MONGODB_AUTH_DB,
|
|
12
|
-
} = process.env;
|
|
13
|
-
|
|
14
|
-
// mongodb connection
|
|
15
|
-
let connection_string = `mongodb://localhost:27017/jxp`;
|
|
16
|
-
if (config.mongo && config.mongo.connection_string) {
|
|
17
|
-
connection_string = config.mongo.connection_string;
|
|
18
|
-
console.warn("`config` to be deprecated in favour of dotenv in future versions");
|
|
19
|
-
}
|
|
20
|
-
if (MONGODB_HOST) {
|
|
21
|
-
connection_string = `mongodb://${ (MONGODB_USER && MONGODB_PASSWORD) ? `${MONGODB_USER}:${MONGODB_PASSWORD}@` : '' }${MONGODB_HOST}:${MONGODB_PORT}/${MONGODB_NAME}?${ (MONGODB_AUTH_DB) ? `authSource=${MONGODB_AUTH_DB}` : '' }`
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = connection_string;
|
package/libs/datamunging.js
DELETED
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
var _ = require("underscore");
|
|
2
|
-
|
|
3
|
-
var input1 = {
|
|
4
|
-
due_date: '2016-02-01T00:00:00Z',
|
|
5
|
-
from_document: '',
|
|
6
|
-
allow_online_payment: 'false',
|
|
7
|
-
paid: 'true',
|
|
8
|
-
locked: 'false',
|
|
9
|
-
customer_id: '2446859',
|
|
10
|
-
modified: '2016-02-02T15:09:06.983',
|
|
11
|
-
created: '2016-02-01T21:09:37.873',
|
|
12
|
-
date: '2016-02-01T00:00:00Z',
|
|
13
|
-
inclusive: 'false',
|
|
14
|
-
discount_percentage: '0',
|
|
15
|
-
tax_reference: '',
|
|
16
|
-
discount: '0',
|
|
17
|
-
amount_due: '0',
|
|
18
|
-
printed: 'false',
|
|
19
|
-
editable: 'true',
|
|
20
|
-
has_attachments: 'false',
|
|
21
|
-
has_notes: 'false',
|
|
22
|
-
has_anticipated_date: 'false',
|
|
23
|
-
'lines[0][SelectionId]': '6824935',
|
|
24
|
-
'lines[0][TaxTypeId]': '965302',
|
|
25
|
-
'lines[0][ID]': '74465675',
|
|
26
|
-
'lines[0][LineType]': '0',
|
|
27
|
-
'lines[0][Quantity]': '1',
|
|
28
|
-
'lines[0][Unit]': '',
|
|
29
|
-
'lines[0][TaxPercentage]': '0.14',
|
|
30
|
-
'lines[0][DiscountPercentage]': '0',
|
|
31
|
-
'lines[0][Discount]': '0',
|
|
32
|
-
'lines[1][ID]': '74465676',
|
|
33
|
-
'lines[1][LineType]': '0',
|
|
34
|
-
'lines[1][Quantity]': '4',
|
|
35
|
-
'lines[1][Unit]': '',
|
|
36
|
-
'lines[1][TaxPercentage]': '0.14',
|
|
37
|
-
'lines[1][DiscountPercentage]': '0',
|
|
38
|
-
'lines[1][Discount]': '0',
|
|
39
|
-
'lines[1][Comments]': '',
|
|
40
|
-
location: '547d506b184d110c0601314c',
|
|
41
|
-
id: '93490358',
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
var test1 = {
|
|
45
|
-
due_date: '2016-02-01T00:00:00Z',
|
|
46
|
-
from_document: '',
|
|
47
|
-
allow_online_payment: 'false',
|
|
48
|
-
paid: 'true',
|
|
49
|
-
locked: 'false',
|
|
50
|
-
customer_id: '2446859',
|
|
51
|
-
modified: '2016-02-02T15:09:06.983',
|
|
52
|
-
created: '2016-02-01T21:09:37.873',
|
|
53
|
-
date: '2016-02-01T00:00:00Z',
|
|
54
|
-
inclusive: 'false',
|
|
55
|
-
discount_percentage: '0',
|
|
56
|
-
tax_reference: '',
|
|
57
|
-
discount: '0',
|
|
58
|
-
amount_due: '0',
|
|
59
|
-
printed: 'false',
|
|
60
|
-
editable: 'true',
|
|
61
|
-
has_attachments: 'false',
|
|
62
|
-
has_notes: 'false',
|
|
63
|
-
has_anticipated_date: 'false',
|
|
64
|
-
lines:
|
|
65
|
-
[{
|
|
66
|
-
SelectionId: '6824935',
|
|
67
|
-
TaxTypeId: '965302',
|
|
68
|
-
ID: '74465675',
|
|
69
|
-
LineType: '0',
|
|
70
|
-
Quantity: '1',
|
|
71
|
-
Unit: '',
|
|
72
|
-
TaxPercentage: '0.14',
|
|
73
|
-
DiscountPercentage: '0',
|
|
74
|
-
Discount: '0'
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
ID: '74465676',
|
|
78
|
-
LineType: '0',
|
|
79
|
-
Quantity: '4',
|
|
80
|
-
Unit: '',
|
|
81
|
-
TaxPercentage: '0.14',
|
|
82
|
-
DiscountPercentage: '0',
|
|
83
|
-
Discount: '0',
|
|
84
|
-
Comments: ''
|
|
85
|
-
}],
|
|
86
|
-
location: '547d506b184d110c0601314c',
|
|
87
|
-
id: '93490358'
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
input2 = {
|
|
91
|
-
'test[0][Yo]': "0Yo",
|
|
92
|
-
'test[0][No]': '0No',
|
|
93
|
-
'test[1][Yo]': "1Yo",
|
|
94
|
-
'test[1][No]': '1No',
|
|
95
|
-
'test[3][No][Yo][0][Lo]': '2NoYo0Lo',
|
|
96
|
-
normalProperty: 123
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
test2 = {
|
|
100
|
-
test: [
|
|
101
|
-
{
|
|
102
|
-
Yo: "0Yo",
|
|
103
|
-
No: "0No"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
Yo: "1Yo",
|
|
107
|
-
No: "1No"
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
No: {
|
|
111
|
-
Yo: [
|
|
112
|
-
{ Lo: "2NoYo0Lo" }
|
|
113
|
-
]
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
],
|
|
117
|
-
normalProperty: 123
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
input3 = {
|
|
121
|
-
'test[0][Yo]': "0Yo",
|
|
122
|
-
'test[0][No]': '0No',
|
|
123
|
-
'test[1][Yo]': "1Yo",
|
|
124
|
-
'test[1][No]': '1No',
|
|
125
|
-
normalProperty: 123
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
test3 = {
|
|
129
|
-
test: [
|
|
130
|
-
{
|
|
131
|
-
Yo: "0Yo",
|
|
132
|
-
No: "0No"
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
Yo: "1Yo",
|
|
136
|
-
No: "1No"
|
|
137
|
-
}
|
|
138
|
-
],
|
|
139
|
-
normalProperty: 123
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
input4 = {
|
|
143
|
-
'test[Blah][Yack]': 'BlahYack',
|
|
144
|
-
'test[Blah][Blah]': 'BlahBlah'
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
test4 = {
|
|
148
|
-
test: {
|
|
149
|
-
Blah: {
|
|
150
|
-
Yack: 'BlahYack',
|
|
151
|
-
Blah: 'BlahBlah'
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
var arrayMatch = /\[\d+\]/;
|
|
157
|
-
var objMatch = /\[[a-zA-Z][a-zA-Z\d]*\]/;
|
|
158
|
-
var allMatch = /^[a-zA-Z\d_\-]+|\[[a-zA-Z\d_\-][a-zA-Z_\-\d]*\]|\[\d+\]/g;
|
|
159
|
-
|
|
160
|
-
/* Copyright (C) 2012-2014 Kurt Milam - http://xioup.com | Source: https://gist.github.com/1868955
|
|
161
|
-
*
|
|
162
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
163
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
164
|
-
*
|
|
165
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
166
|
-
**/
|
|
167
|
-
|
|
168
|
-
// Based conceptually on the _.extend() function in underscore.js ( see http://documentcloud.github.com/underscore/#extend for more details )
|
|
169
|
-
|
|
170
|
-
function deepExtend(obj, depth = 0) {
|
|
171
|
-
const MAX_DEPTH = 20; // Prevent infinite recursion
|
|
172
|
-
if (depth > MAX_DEPTH) {
|
|
173
|
-
console.warn('Maximum depth exceeded in deepExtend');
|
|
174
|
-
return obj;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
var parentRE = /#{\s*?_\s*?}/,
|
|
178
|
-
slice = Array.prototype.slice;
|
|
179
|
-
|
|
180
|
-
_.each(slice.call(arguments, 1), function (source) {
|
|
181
|
-
for (var prop in source) {
|
|
182
|
-
if (_.isUndefined(obj[prop]) || _.isFunction(obj[prop]) || _.isNull(source[prop]) || _.isDate(source[prop])) {
|
|
183
|
-
obj[prop] = source[prop];
|
|
184
|
-
}
|
|
185
|
-
else if (_.isString(source[prop]) && parentRE.test(source[prop])) {
|
|
186
|
-
if (_.isString(obj[prop])) {
|
|
187
|
-
obj[prop] = source[prop].replace(parentRE, obj[prop]);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else if (_.isArray(obj[prop]) || _.isArray(source[prop])) {
|
|
191
|
-
if (!_.isArray(obj[prop]) || !_.isArray(source[prop])) {
|
|
192
|
-
throw new Error('Trying to combine an array with a non-array (' + prop + ')');
|
|
193
|
-
} else {
|
|
194
|
-
obj[prop] = _.reject(_.deepExtend(_.clone(obj[prop]), source[prop], depth + 1), function (item) { return _.isNull(item); });
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else if (_.isObject(obj[prop]) || _.isObject(source[prop])) {
|
|
198
|
-
if (!_.isObject(obj[prop]) || !_.isObject(source[prop])) {
|
|
199
|
-
throw new Error('Trying to combine an object with a non-object (' + prop + ')');
|
|
200
|
-
} else {
|
|
201
|
-
obj[prop] = _.deepExtend(_.clone(obj[prop]), source[prop], depth + 1);
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
obj[prop] = source[prop];
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
return obj;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
_.mixin({ 'deepExtend': deepExtend });
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Dependency: underscore.js ( http://documentcloud.github.com/underscore/ )
|
|
215
|
-
*
|
|
216
|
-
* Mix it in with underscore.js:
|
|
217
|
-
* _.mixin({deepExtend: deepExtend});
|
|
218
|
-
*
|
|
219
|
-
* Call it like this:
|
|
220
|
-
* var myObj = _.deepExtend(grandparent, child, grandchild, greatgrandchild)
|
|
221
|
-
*
|
|
222
|
-
* Notes:
|
|
223
|
-
* Keep it DRY.
|
|
224
|
-
* This function is especially useful if you're working with JSON config documents. It allows you to create a default
|
|
225
|
-
* config document with the most common settings, then override those settings for specific cases. It accepts any
|
|
226
|
-
* number of objects as arguments, giving you fine-grained control over your config document hierarchy.
|
|
227
|
-
*
|
|
228
|
-
* Special Features and Considerations:
|
|
229
|
-
* - parentRE allows you to concatenate strings. example:
|
|
230
|
-
* var obj = _.deepExtend({url: "www.example.com"}, {url: "http://#{_}/path/to/file.html"});
|
|
231
|
-
* console.log(obj.url);
|
|
232
|
-
* output: "http://www.example.com/path/to/file.html"
|
|
233
|
-
*
|
|
234
|
-
* - parentRE also acts as a placeholder, which can be useful when you need to change one value in an array, while
|
|
235
|
-
* leaving the others untouched. example:
|
|
236
|
-
* var arr = _.deepExtend([100, {id: 1234}, true, "foo", [250, 500]],
|
|
237
|
-
* ["#{_}", "#{_}", false, "#{_}", "#{_}"]);
|
|
238
|
-
* console.log(arr);
|
|
239
|
-
* output: [100, {id: 1234}, false, "foo", [250, 500]]
|
|
240
|
-
*
|
|
241
|
-
* - The previous example can also be written like this:
|
|
242
|
-
* var arr = _.deepExtend([100, {id:1234}, true, "foo", [250, 500]],
|
|
243
|
-
* ["#{_}", {}, false, "#{_}", []]);
|
|
244
|
-
* console.log(arr);
|
|
245
|
-
* output: [100, {id: 1234}, false, "foo", [250, 500]]
|
|
246
|
-
*
|
|
247
|
-
* - And also like this:
|
|
248
|
-
* var arr = _.deepExtend([100, {id:1234}, true, "foo", [250, 500]],
|
|
249
|
-
* ["#{_}", {}, false]);
|
|
250
|
-
* console.log(arr);
|
|
251
|
-
* output: [100, {id: 1234}, false, "foo", [250, 500]]
|
|
252
|
-
*
|
|
253
|
-
* - Array order is important. example:
|
|
254
|
-
* var arr = _.deepExtend([1, 2, 3, 4], [1, 4, 3, 2]);
|
|
255
|
-
* console.log(arr);
|
|
256
|
-
* output: [1, 4, 3, 2]
|
|
257
|
-
*
|
|
258
|
-
* - You can remove an array element set in a parent object by setting the same index value to null in a child object.
|
|
259
|
-
* example:
|
|
260
|
-
* var obj = _.deepExtend({arr: [1, 2, 3, 4]}, {arr: ["#{_}", null]});
|
|
261
|
-
* console.log(obj.arr);
|
|
262
|
-
* output: [1, 3, 4]
|
|
263
|
-
*
|
|
264
|
-
**/
|
|
265
|
-
|
|
266
|
-
function isNumeric(n) {
|
|
267
|
-
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function isArray(a) {
|
|
271
|
-
return Array.isArray(a);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
var assignPropVal = function (parts, result, val, depth = 0) {
|
|
275
|
-
const MAX_DEPTH = 20; // Prevent infinite recursion
|
|
276
|
-
if (depth > MAX_DEPTH) {
|
|
277
|
-
console.warn('Maximum depth exceeded in assignPropVal');
|
|
278
|
-
return result;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
var part = parts.shift().replace(/\[|\]/g, "");
|
|
282
|
-
if (parts.length) {
|
|
283
|
-
if (isNumeric(parts[0].replace(/\[|\]/g, ""))) {
|
|
284
|
-
result[part] = [];
|
|
285
|
-
} else {
|
|
286
|
-
result[part] = {};
|
|
287
|
-
}
|
|
288
|
-
assignPropVal(parts, result[part], val, depth + 1);
|
|
289
|
-
} else {
|
|
290
|
-
result[part] = val;
|
|
291
|
-
}
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
var deserialize = function (input) {
|
|
296
|
-
// console.log("INPUT", input);
|
|
297
|
-
var result = {};
|
|
298
|
-
var newobj = {};
|
|
299
|
-
for (prop in input) {
|
|
300
|
-
var parts = prop.match(allMatch);
|
|
301
|
-
// console.log(prop, parts);
|
|
302
|
-
var val = input[prop];
|
|
303
|
-
if (parts) {
|
|
304
|
-
var tmp = assignPropVal(parts, result, val, 0);
|
|
305
|
-
newobj = _.deepExtend(tmp);
|
|
306
|
-
} else {
|
|
307
|
-
// console.log("NOT ARRAY", parts);
|
|
308
|
-
newobj[prop] = input[prop];
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
// input = newobj;
|
|
312
|
-
// console.log("Munge!", newobj);
|
|
313
|
-
return newobj;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
var runTest = function (name, input, test) {
|
|
317
|
-
var result = deserialize(input);
|
|
318
|
-
if (_.isEqual(result, test)) {
|
|
319
|
-
console.log("PASSED " + name);
|
|
320
|
-
} else {
|
|
321
|
-
console.log("FAILED " + name);
|
|
322
|
-
console.log(result);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
var test = function () {
|
|
327
|
-
runTest("Test 1", input1, test1);
|
|
328
|
-
runTest("Test 2", input2, test2);
|
|
329
|
-
runTest("Test 3", input3, test3);
|
|
330
|
-
runTest("Test 4", input4, test4);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
module.exports = {
|
|
334
|
-
deserialize: deserialize
|
|
335
|
-
}
|