beech-api 3.9.0-beta.9-rc → 3.9.75
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/LICENSE +21 -21
- package/README.md +1715 -1649
- package/index.js +2 -2
- package/package.json +92 -84
- package/packages/cli/beech +9 -10
- package/packages/cli/bin/beech-app.js +390 -390
- package/packages/cli/bin/beech-service.js +263 -170
- package/packages/cli/core/auth/Credentials.js +174 -174
- package/packages/cli/core/auth/Passport.js +664 -664
- package/packages/cli/core/auth/_Request.js +12 -12
- package/packages/cli/core/configure/_gitignore +16 -15
- package/packages/cli/core/configure/_sequelizerc +9 -9
- package/packages/cli/core/configure/app.config-basic.js +55 -55
- package/packages/cli/core/configure/app.config-sequelize.js +88 -88
- package/packages/cli/core/configure/beech.config.js +9 -9
- package/packages/cli/core/configure/global.config-basic.js +8 -8
- package/packages/cli/core/configure/global.config-sequelize.js +8 -8
- package/packages/cli/core/configure/jest.config.js +6 -6
- package/packages/cli/core/configure/jsconfig.json +8 -7
- package/packages/cli/core/configure/passport.config.js +97 -97
- package/packages/cli/core/databases/mysql.js +94 -95
- package/packages/cli/core/databases/sequelize.js +187 -188
- package/packages/cli/core/databases/test.js +250 -255
- package/packages/cli/core/file-walk/file-walk.js +35 -35
- package/packages/cli/core/generator/_endpoints +15 -15
- package/packages/cli/core/generator/_endpoints_basic +42 -42
- package/packages/cli/core/generator/_help +26 -18
- package/packages/cli/core/generator/_help_create +10 -10
- package/packages/cli/core/generator/_help_service +10 -10
- package/packages/cli/core/generator/_helpers +9 -9
- package/packages/cli/core/generator/_helpers_basic +22 -22
- package/packages/cli/core/generator/_models +6 -6
- package/packages/cli/core/generator/_models_basic +13 -13
- package/packages/cli/core/generator/_package +23 -19
- package/packages/cli/core/generator/_scheduler +32 -32
- package/packages/cli/core/generator/_spec +29 -29
- package/packages/cli/core/generator/index.js +1081 -992
- package/packages/cli/core/helpers/2fa.js +106 -106
- package/packages/cli/core/helpers/math.js +115 -115
- package/packages/cli/core/helpers/poolEntity.js +103 -103
- package/packages/cli/core/index.js +264 -266
- package/packages/cli/core/middleware/express/duplicateRequest.js +16 -16
- package/packages/cli/core/middleware/express/jwtCheckAllow.js +85 -85
- package/packages/cli/core/middleware/express/rateLimit.js +29 -29
- package/packages/cli/core/middleware/express/slowDown.js +2 -2
- package/packages/cli/core/middleware/index.js +6 -6
- package/packages/cli/core/middleware/origin/guard/advance.js +75 -75
- package/packages/cli/core/middleware/origin/whitelist/cors.js +94 -94
- package/packages/cli/core/services/http.express.js +481 -481
- package/packages/cli/core/test/check-node.js +21 -21
- package/packages/cli/core/test/utils.js +7 -7
- package/packages/cli/entry +10 -0
- package/packages/lib/index.js +6 -6
- package/packages/lib/src/endpoint.js +947 -885
- package/packages/lib/src/guard.js +60 -60
- package/packages/lib/src/salt.js +3 -3
- package/packages/lib/src/schema.js +96 -96
- package/packages/lib/src/specificExpress.js +7 -7
- package/packages/lib/src/user.js +271 -271
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
{{requireSomething}}
|
|
2
|
-
exports.init = () => {
|
|
3
|
-
|
|
4
|
-
// Initiate with Basic request currently support GET, POST, PUT, PATCH and DELETE
|
|
5
|
-
|
|
6
|
-
endpoint.get("/{{endpoint}}", Credentials, (req, res) => {
|
|
7
|
-
// @return
|
|
8
|
-
res.json({
|
|
9
|
-
code: 200,
|
|
10
|
-
status: "SUCCESS",
|
|
11
|
-
message: "GET request at /{{endpoint}}",
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
endpoint.post("/{{endpoint}}", Credentials, (req, res) => {
|
|
16
|
-
let id = req.body.id;
|
|
17
|
-
let name = req.body.name;
|
|
18
|
-
// @return
|
|
19
|
-
res.json({
|
|
20
|
-
code: 200,
|
|
21
|
-
message: "POST request at /{{endpoint}}",
|
|
22
|
-
status: "SUCCESS",
|
|
23
|
-
result: {
|
|
24
|
-
id,
|
|
25
|
-
name,
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
endpoint.put("/{{endpoint}}/:id", Credentials, (req, res) => {
|
|
31
|
-
let id = req.params.id;
|
|
32
|
-
// @return
|
|
33
|
-
res.json({
|
|
34
|
-
code: 200,
|
|
35
|
-
status: "SUCCESS",
|
|
36
|
-
message: "PUT request at /{{endpoint}}/" + id,
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Create new Endpoint, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#part-of-generate-file
|
|
41
|
-
|
|
42
|
-
};
|
|
1
|
+
{{requireSomething}}
|
|
2
|
+
exports.init = () => {
|
|
3
|
+
|
|
4
|
+
// Initiate with Basic request currently support GET, POST, PUT, PATCH and DELETE
|
|
5
|
+
|
|
6
|
+
endpoint.get("/{{endpoint}}", Credentials, (req, res) => {
|
|
7
|
+
// @return
|
|
8
|
+
res.json({
|
|
9
|
+
code: 200,
|
|
10
|
+
status: "SUCCESS",
|
|
11
|
+
message: "GET request at /{{endpoint}}",
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
endpoint.post("/{{endpoint}}", Credentials, (req, res) => {
|
|
16
|
+
let id = req.body.id;
|
|
17
|
+
let name = req.body.name;
|
|
18
|
+
// @return
|
|
19
|
+
res.json({
|
|
20
|
+
code: 200,
|
|
21
|
+
message: "POST request at /{{endpoint}}",
|
|
22
|
+
status: "SUCCESS",
|
|
23
|
+
result: {
|
|
24
|
+
id,
|
|
25
|
+
name,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
endpoint.put("/{{endpoint}}/:id", Credentials, (req, res) => {
|
|
31
|
+
let id = req.params.id;
|
|
32
|
+
// @return
|
|
33
|
+
res.json({
|
|
34
|
+
code: 200,
|
|
35
|
+
status: "SUCCESS",
|
|
36
|
+
message: "PUT request at /{{endpoint}}/" + id,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Create new Endpoint, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#part-of-generate-file
|
|
41
|
+
|
|
42
|
+
};
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
Usage:
|
|
3
|
-
$ beech [options] [arguments] [special]
|
|
4
|
-
|
|
5
|
-
Options:
|
|
6
|
-
?, -h, --help Display this help message.
|
|
7
|
-
-v, --version Display the application version.
|
|
8
|
-
|
|
9
|
-
The following commands are available:
|
|
10
|
-
|
|
11
|
-
$ beech make <endpoint> Create a new Endpoints and unit test file,
|
|
12
|
-
You might using [special] `-R, --require`
|
|
13
|
-
for choose Model(s) used to endpoint file.
|
|
14
|
-
|
|
15
|
-
$ beech make <
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
|
|
2
|
+
Usage:
|
|
3
|
+
$ beech [options] [arguments] [special]
|
|
4
|
+
|
|
5
|
+
Options:
|
|
6
|
+
?, -h, --help Display this help message.
|
|
7
|
+
-v, --version Display the application version.
|
|
8
|
+
|
|
9
|
+
The following commands are available:
|
|
10
|
+
|
|
11
|
+
$ beech make <endpoint> Create a new Endpoints and unit test file,
|
|
12
|
+
You might using [special] `-R, --require`
|
|
13
|
+
for choose Model(s) used to endpoint file.
|
|
14
|
+
|
|
15
|
+
$ beech make <model> -M, --model Create a new Models file, You might using
|
|
16
|
+
[special] `--no-comment` for ignore comment
|
|
17
|
+
Table Property in your Schema.
|
|
18
|
+
|
|
19
|
+
$ beech update model <model_name> Update new Table Structure for latest, You
|
|
20
|
+
might using [special] `--no-comment` for
|
|
21
|
+
ignore comment Table Property in your Schema.
|
|
22
|
+
|
|
23
|
+
$ beech make <helper> --helper Create a new Helpers file.
|
|
24
|
+
$ beech passport init Initialize authentication with passport-jwt.
|
|
25
|
+
$ beech skd init Initialize Job Scheduler file.
|
|
26
|
+
$ beech key:generate, key:gen Re-Generate application key (Dangerous!).
|
|
19
27
|
$ beech hash:<text> Hash text for Access to Database connection.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Usage:
|
|
3
|
-
$ beech-app create <app-name>
|
|
4
|
-
$ beech-app update [arguments]
|
|
5
|
-
|
|
6
|
-
Options:
|
|
7
|
-
?, -h, --help Display this help message.
|
|
8
|
-
-v, --version Display the application version.update
|
|
9
|
-
|
|
10
|
-
Arguments:
|
|
1
|
+
|
|
2
|
+
Usage:
|
|
3
|
+
$ beech-app create <app-name>
|
|
4
|
+
$ beech-app update [arguments]
|
|
5
|
+
|
|
6
|
+
Options:
|
|
7
|
+
?, -h, --help Display this help message.
|
|
8
|
+
-v, --version Display the application version.update
|
|
9
|
+
|
|
10
|
+
Arguments:
|
|
11
11
|
-g, --global Global upgrade The beech-api to latest version.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Usage:
|
|
3
|
-
$ beech-service [options] [arguments]
|
|
4
|
-
|
|
5
|
-
Options:
|
|
6
|
-
?, -h, --help Display this help message.
|
|
7
|
-
serve Start development service.
|
|
8
|
-
build Build production.
|
|
9
|
-
|
|
10
|
-
Arguments:
|
|
1
|
+
|
|
2
|
+
Usage:
|
|
3
|
+
$ beech-service [options] [arguments]
|
|
4
|
+
|
|
5
|
+
Options:
|
|
6
|
+
?, -h, --help Display this help message.
|
|
7
|
+
serve Start development service.
|
|
8
|
+
build Build production.
|
|
9
|
+
|
|
10
|
+
Arguments:
|
|
11
11
|
-S, --silent Disabled notify compiler.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
|
|
3
|
-
// textUpperCase(text) {
|
|
4
|
-
// return text.toUpperCase();
|
|
5
|
-
// },
|
|
6
|
-
// textLowerCase(text) {
|
|
7
|
-
// return text.toLowerCase();
|
|
8
|
-
// }
|
|
9
|
-
|
|
1
|
+
module.exports = {
|
|
2
|
+
|
|
3
|
+
// textUpperCase(text) {
|
|
4
|
+
// return text.toUpperCase();
|
|
5
|
+
// },
|
|
6
|
+
// textLowerCase(text) {
|
|
7
|
+
// return text.toLowerCase();
|
|
8
|
+
// }
|
|
9
|
+
|
|
10
10
|
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
|
|
3
|
-
textLowerCase(text) {
|
|
4
|
-
return text.toLowerCase();
|
|
5
|
-
},
|
|
6
|
-
|
|
7
|
-
textUpperCase(text) {
|
|
8
|
-
return text.toUpperCase();
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
digit9(number) {
|
|
12
|
-
return ('000000000' + number).slice(-9);
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
dateToThai(date) {
|
|
16
|
-
return result = date.toLocaleDateString('th-TH', {
|
|
17
|
-
year: 'numeric',
|
|
18
|
-
month: 'long',
|
|
19
|
-
day: 'numeric',
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
|
|
1
|
+
module.exports = {
|
|
2
|
+
|
|
3
|
+
textLowerCase(text) {
|
|
4
|
+
return text.toLowerCase();
|
|
5
|
+
},
|
|
6
|
+
|
|
7
|
+
textUpperCase(text) {
|
|
8
|
+
return text.toUpperCase();
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
digit9(number) {
|
|
12
|
+
return ('000000000' + number).slice(-9);
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
dateToThai(date) {
|
|
16
|
+
return result = date.toLocaleDateString('th-TH', {
|
|
17
|
+
year: 'numeric',
|
|
18
|
+
month: 'long',
|
|
19
|
+
day: 'numeric',
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
|
|
23
23
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { Schema } = require("beech-api");
|
|
2
|
-
// {{modelNameUppercase}} structure
|
|
3
|
-
{{modelStructure}}
|
|
4
|
-
// Asign more DataTypes, Learn more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
|
|
5
|
-
|
|
6
|
-
module.exports = { {{modelNameUppercase}} };
|
|
1
|
+
const { Schema } = require("beech-api");
|
|
2
|
+
// {{modelNameUppercase}} structure
|
|
3
|
+
{{modelStructure}}
|
|
4
|
+
// Asign more DataTypes, Learn more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
|
|
5
|
+
|
|
6
|
+
module.exports = { {{modelNameUppercase}} };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
|
|
3
|
-
// Example basic function get data from table {{modelName}}
|
|
4
|
-
findAll() {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
// calling Pool connection name by `sql.{{dbSelected}}`
|
|
7
|
-
sql.{{dbSelected}}.query("SELECT * FROM {{modelName}}", (err, results) => {
|
|
8
|
-
if (err) reject(err);
|
|
9
|
-
resolve(results);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
},
|
|
13
|
-
|
|
1
|
+
module.exports = {
|
|
2
|
+
|
|
3
|
+
// Example basic function get data from table {{modelName}}
|
|
4
|
+
findAll() {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
// calling Pool connection name by `sql.{{dbSelected}}`
|
|
7
|
+
sql.{{dbSelected}}.query("SELECT * FROM {{modelName}}", (err, results) => {
|
|
8
|
+
if (err) reject(err);
|
|
9
|
+
resolve(results);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
|
|
14
14
|
}
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "application",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "The project is powered by Beech API framework",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"predev": "node ./node_modules/beech-api/packages/cli/core/test/check-node.js",
|
|
9
|
-
"prebuild": "node ./node_modules/beech-api/packages/cli/core/test/check-node.js",
|
|
10
|
-
"build": "set NODE_ENV=production&& beech-service build",
|
|
11
|
-
"dev": "beech-service serve",
|
|
12
|
-
"test": "node ./node_modules/jest/bin/jest __tests__ -o --watch --config"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"beech-api": "^3.9.0"
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"jest": "^
|
|
19
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "application",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The project is powered by Beech API framework",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"predev": "node ./node_modules/beech-api/packages/cli/core/test/check-node.js",
|
|
9
|
+
"prebuild": "node ./node_modules/beech-api/packages/cli/core/test/check-node.js",
|
|
10
|
+
"build": "set NODE_ENV=production&& beech-service build",
|
|
11
|
+
"dev": "beech-service serve",
|
|
12
|
+
"test": "node ./node_modules/jest/bin/jest __tests__ -o --watch --config"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"beech-api": "^3.9.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"jest": "^30.2.0"
|
|
19
|
+
},
|
|
20
|
+
"overrides": {
|
|
21
|
+
"cross-spawn": "^7.0.5",
|
|
22
|
+
"lru.min": "1.1.1"
|
|
23
|
+
}
|
|
20
24
|
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
const CronJob = require("cron").CronJob;
|
|
2
|
-
//const Users = require("@/models/Users");
|
|
3
|
-
|
|
4
|
-
exports.init = () => {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* TODO something.
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// const getUsers = async () => {
|
|
12
|
-
// try {
|
|
13
|
-
// const users = await Users.findAll();
|
|
14
|
-
// console.log(users);
|
|
15
|
-
// } catch (error) {
|
|
16
|
-
// console.error(error);
|
|
17
|
-
// }
|
|
18
|
-
// };
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Job schedule: seconds minutes hours dayOfMonth month dayOfWeek
|
|
22
|
-
* Learn more: https://github.com/kelektiv/node-cron
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
new CronJob("0 0 0 * * *", () => {
|
|
26
|
-
// Run job.
|
|
27
|
-
|
|
28
|
-
// getUsers();
|
|
29
|
-
|
|
30
|
-
}, null, true, "Asia/Bangkok");
|
|
31
|
-
|
|
32
|
-
};
|
|
1
|
+
const CronJob = require("cron").CronJob;
|
|
2
|
+
//const Users = require("@/models/Users");
|
|
3
|
+
|
|
4
|
+
exports.init = () => {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TODO something.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// const getUsers = async () => {
|
|
12
|
+
// try {
|
|
13
|
+
// const users = await Users.findAll();
|
|
14
|
+
// console.log(users);
|
|
15
|
+
// } catch (error) {
|
|
16
|
+
// console.error(error);
|
|
17
|
+
// }
|
|
18
|
+
// };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Job schedule: seconds minutes hours dayOfMonth month dayOfWeek
|
|
22
|
+
* Learn more: https://github.com/kelektiv/node-cron
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
new CronJob("0 0 0 * * *", () => {
|
|
26
|
+
// Run job.
|
|
27
|
+
|
|
28
|
+
// getUsers();
|
|
29
|
+
|
|
30
|
+
}, null, true, "Asia/Bangkok");
|
|
31
|
+
|
|
32
|
+
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const endpoint = baseUrl.concat("/{{endpoint}}");
|
|
2
|
-
/**
|
|
3
|
-
* An asynchronous test will fail after 5000 ms if done() is not called.
|
|
4
|
-
* This timeout can be changed by setting TIMEOUT_INTERVAL or by passing
|
|
5
|
-
* a timeout interval in the specification.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
describe("Test endpoint : " + endpoint, () => {
|
|
10
|
-
it("Truthy!", () => {
|
|
11
|
-
expect("{{endpoint}}").toBeTruthy();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("Say hello!", () => {
|
|
15
|
-
expect("Hello {{endpointName}}").toEqual("Hello {{endpointName}}");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("Respond with basic GET status code 200", (done) => {
|
|
19
|
-
axios
|
|
20
|
-
.get(endpoint)
|
|
21
|
-
.then((res) => {
|
|
22
|
-
expect(200).toEqual(res.data.code);
|
|
23
|
-
done();
|
|
24
|
-
})
|
|
25
|
-
.catch(() => {
|
|
26
|
-
expect(401).toEqual(401);
|
|
27
|
-
done();
|
|
28
|
-
});
|
|
29
|
-
});
|
|
1
|
+
const endpoint = baseUrl.concat("/{{endpoint}}");
|
|
2
|
+
/**
|
|
3
|
+
* An asynchronous test will fail after 5000 ms if done() is not called.
|
|
4
|
+
* This timeout can be changed by setting TIMEOUT_INTERVAL or by passing
|
|
5
|
+
* a timeout interval in the specification.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
describe("Test endpoint : " + endpoint, () => {
|
|
10
|
+
it("Truthy!", () => {
|
|
11
|
+
expect("{{endpoint}}").toBeTruthy();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("Say hello!", () => {
|
|
15
|
+
expect("Hello {{endpointName}}").toEqual("Hello {{endpointName}}");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("Respond with basic GET status code 200", (done) => {
|
|
19
|
+
axios
|
|
20
|
+
.get(endpoint)
|
|
21
|
+
.then((res) => {
|
|
22
|
+
expect(200).toEqual(res.data.code);
|
|
23
|
+
done();
|
|
24
|
+
})
|
|
25
|
+
.catch(() => {
|
|
26
|
+
expect(401).toEqual(401);
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
30
|
});
|