beech-api 3.8.0 → 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 -1244
- package/index.js +2 -2
- package/package.json +92 -83
- package/packages/cli/beech +9 -10
- package/packages/cli/bin/beech-app.js +389 -389
- package/packages/cli/bin/beech-service.js +262 -132
- package/packages/cli/core/auth/Credentials.js +174 -147
- package/packages/cli/core/auth/Passport.js +664 -592
- 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 -179
- package/packages/cli/core/databases/test.js +251 -170
- 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 -29
- package/packages/cli/core/generator/_models_basic +13 -22
- package/packages/cli/core/generator/_package +23 -20
- package/packages/cli/core/generator/_scheduler +32 -22
- package/packages/cli/core/generator/_spec +29 -29
- package/packages/cli/core/generator/index.js +1081 -738
- package/packages/cli/core/helpers/2fa.js +106 -85
- package/packages/cli/core/helpers/math.js +115 -103
- package/packages/cli/core/helpers/poolEntity.js +103 -59
- package/packages/cli/core/index.js +264 -188
- package/packages/cli/core/middleware/express/duplicateRequest.js +16 -12
- package/packages/cli/core/middleware/express/jwtCheckAllow.js +86 -68
- package/packages/cli/core/middleware/express/rateLimit.js +29 -17
- 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 -74
- package/packages/cli/core/middleware/origin/whitelist/cors.js +94 -94
- package/packages/cli/core/services/http.express.js +481 -441
- package/packages/cli/core/test/check-node.js +21 -0
- 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 -532
- package/packages/lib/src/guard.js +60 -60
- package/packages/lib/src/salt.js +3 -3
- package/packages/lib/src/schema.js +96 -93
- package/packages/lib/src/specificExpress.js +7 -7
- package/packages/lib/src/user.js +271 -271
|
@@ -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,29 +1,6 @@
|
|
|
1
|
-
const { Schema } = require("beech-api");
|
|
2
|
-
// {{modelNameUppercase}} structure
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
autoIncrement: true,
|
|
8
|
-
primaryKey: true,
|
|
9
|
-
},
|
|
10
|
-
examField1: DataTypes.STRING,
|
|
11
|
-
examField3: DataTypes.DATE,
|
|
12
|
-
examField4: {
|
|
13
|
-
type: DataTypes.STRING,
|
|
14
|
-
allowNull: false,
|
|
15
|
-
// set(value) {
|
|
16
|
-
// this.setDataValue("examField4", md5(value));
|
|
17
|
-
// },
|
|
18
|
-
},
|
|
19
|
-
createdAt: DataTypes.DATE,
|
|
20
|
-
updatedAt: DataTypes.DATE,
|
|
21
|
-
// Asign more DataTypes, Learn more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Example basic function Get one data by id
|
|
25
|
-
function exampleFindOne{{modelNameUppercase}}ById(id) {
|
|
26
|
-
return {{modelNameUppercase}}.findOne({ where: { id: id } });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = { {{modelNameUppercase}}, exampleFindOne{{modelNameUppercase}}ById };
|
|
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,23 +1,14 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
|
|
3
|
-
// Example basic function
|
|
4
|
-
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
{ "
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
// calling Pool connection name by `sql.{{dbSelected}}`
|
|
16
|
-
sql.{{dbSelected}}.query("SELECT * FROM {{modelName}}", (err, results) => {
|
|
17
|
-
if (err) reject(err);
|
|
18
|
-
resolve(results);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
|
|
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
|
+
|
|
23
14
|
}
|
|
@@ -1,21 +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
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
}
|
|
21
24
|
}
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
//const
|
|
3
|
-
|
|
4
|
-
exports.init = () => {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* TODO something.
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
});
|