beech-api 3.5.7 → 3.5.12

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.
Files changed (33) hide show
  1. package/README.md +1 -1
  2. package/package.json +9 -5
  3. package/packages/cli/beech +2 -2
  4. package/packages/cli/bin/beech-service.js +305 -0
  5. package/packages/cli/bin/beech.js +21 -17
  6. package/packages/cli/core/auth/Passport.js +4 -0
  7. package/packages/cli/core/configure/app.config-sequelize.js +5 -0
  8. package/packages/cli/core/databases/sequelize.js +12 -10
  9. package/packages/cli/core/generator/_package +2 -2
  10. package/packages/cli/core/generator/_service +8 -0
  11. package/packages/cli/core/index.js +2 -1
  12. package/packages/cli/core/services/http.express.js +15 -13
  13. package/packages/package.json +2 -1
  14. package/packages/public/icon/beech_128.png +0 -0
  15. package/packages/src-/Add-on.js +9 -0
  16. package/packages/src-/endpoints/hello-endpoints.js +118 -0
  17. package/packages/src-/endpoints/test2-endpoints.js +75 -0
  18. package/packages/src-/endpoints/testSequalize-endpoints.js +23 -0
  19. package/packages/src-/helpers/Test2.js +11 -0
  20. package/packages/src-/helpers/my/Test.js +11 -0
  21. package/packages/src-/helpers/my/Test2.js +11 -0
  22. package/packages/src-/helpers/my/Test3.js +11 -0
  23. package/packages/src-/helpers/my/Test4.js +11 -0
  24. package/packages/src-/models/Jubu.js +29 -0
  25. package/packages/src-/models/Jubu2.js +20 -0
  26. package/packages/src-/models/Map_master.js +22 -0
  27. package/packages/src-/models/Test.js +29 -0
  28. package/packages/src-/models/Test2.js +29 -0
  29. package/packages/src-/models/User2Sequelize.js +23 -0
  30. package/packages/src-/models/Users-sqlite.js +21 -0
  31. package/packages/src-/models/Users.js +53 -0
  32. package/packages/src-/models/Uuuuuxxx.js +23 -0
  33. package/packages/src-/models/xxx/Uuuuuxxx.js +23 -0
package/README.md CHANGED
@@ -29,7 +29,7 @@
29
29
 
30
30
  ## Environment
31
31
 
32
- - [`Node.js`](https://nodejs.org) >= 10.13.0+ (recommended)
32
+ - [`Node.js`](https://nodejs.org) >= 14.19.0+ (recommended)
33
33
  - `npm` >= 6.4.1+ or `yarn` >= 1.22.4+
34
34
 
35
35
  ## Installation
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "beech-api",
3
- "version": "3.5.7",
3
+ "version": "3.5.12",
4
4
  "description": "Command line interface for rapid Beech API development",
5
5
  "keywords": [
6
+ "api",
7
+ "api-framework",
6
8
  "beech-api",
7
9
  "cli",
8
- "api",
9
- "nodejs",
10
- "api-framework"
10
+ "nodejs"
11
11
  ],
12
12
  "license": "MIT",
13
13
  "repository": {
@@ -18,6 +18,7 @@
18
18
  "authors": "bombkiml",
19
19
  "bin": {
20
20
  "beech-app": "./packages/cli/bin/beech.js",
21
+ "beech-service": "./packages/cli/bin/beech-service.js",
21
22
  "beech": "./packages/cli/core/generator/index.js"
22
23
  },
23
24
  "bugs": {
@@ -26,7 +27,7 @@
26
27
  "homepage": "https://github.com/bombkiml/beech-api/blob/master/README.md",
27
28
  "deprecated": false,
28
29
  "engines": {
29
- "node": ">=10.13"
30
+ "node": ">=14.19"
30
31
  },
31
32
  "dependencies": {
32
33
  "app-root-path": "^3.0.0",
@@ -47,6 +48,7 @@
47
48
  "mysql": "^2.18.1",
48
49
  "mysql2": "^2.3.3",
49
50
  "node-cmd": "^3.0.0",
51
+ "node-notifier": "^10.0.1",
50
52
  "passport": "^0.6.0",
51
53
  "passport-facebook": "^3.0.0",
52
54
  "passport-google-oauth": "^2.0.0",
@@ -59,6 +61,8 @@
59
61
  },
60
62
  "devDependencies": {
61
63
  "jest": "^28.1.3",
64
+ "node-dev": "^8.0.0",
65
+ "nodemon": "^3.0.1",
62
66
  "sequelize-cli": "^5.5.1"
63
67
  },
64
68
  "jest": {
@@ -4,8 +4,8 @@
4
4
  * The beech api (cli) package generator and server (bash for developer and production build)
5
5
  *
6
6
  * @author bombkiml
7
- * @version 3.2
8
- * @built Apr 17, 2020 at 00:09:19
7
+ * @version 3.6
8
+ * @built Aug 14, 2023 at 00:09:19
9
9
  *
10
10
  */
11
11
  (process.argv[2]) ? require('./core/generator/index') : require('./core/index')
@@ -0,0 +1,305 @@
1
+ #!/usr/bin/env node
2
+ const logUpdate = require("log-update");
3
+ const notifier = require("node-notifier");
4
+ const path = require("path");
5
+ const clear = require("cli-clear");
6
+ const express = require("express");
7
+ const _app_ = express();
8
+ const Sequelize = require('sequelize');
9
+ let testSql = {};
10
+
11
+ class Beech {
12
+ constructor() {
13
+ this.embed(process.argv)
14
+ .then(() => this.init()
15
+ .then(status => console.log(status))
16
+ .catch(err => {
17
+ throw err;
18
+ })
19
+ );
20
+ }
21
+
22
+ init() {
23
+ return new Promise(async (resolve, reject) => {
24
+ try {
25
+ if (this.option == "serve") {
26
+ let turnNoti = true;
27
+ if (this.argument == "--silent" || this.argument == "-S") {
28
+ turnNoti = false;
29
+ }
30
+ // check project config file exists ?
31
+ if (this.fs.existsSync(this.configFile)) {
32
+ const testServ = _app_.listen(this._config_.main_config.app_port, () => {
33
+ //console.log("Test Started.");
34
+ testServ.close();
35
+ // Start real service.
36
+ this.getStart(turnNoti, (err, res) => {
37
+ if (err) {
38
+ reject("\n Faltal  start service catch.");
39
+ return;
40
+ }
41
+ // show info
42
+ console.clear();
43
+ //console.log(res);
44
+ });
45
+
46
+ });
47
+ } else {
48
+ resolve("\n Faltal  The app.conifg.js file is not found.");
49
+ }
50
+ } else if (!this.option || this.option == "-h" || this.option == "?" || this.option == "--help") {
51
+ // help for see avaliable command
52
+ this.help()
53
+ .then(help => resolve(help))
54
+ .catch(err => reject(err));
55
+ } else {
56
+ resolve("\n Faltal  commnad it's not available.");
57
+ }
58
+ } catch (error) {
59
+ reject(error);
60
+ }
61
+ });
62
+ }
63
+
64
+ filterDbIsTrue(dbConfig, cb) {
65
+ try {
66
+ let dbIsTrue = [];
67
+ dbConfig.filter((e, k) => {
68
+ if (e.is_connect) {
69
+ dbIsTrue.push(e);
70
+ }
71
+ if (dbConfig.length == k + 1) {
72
+ cb(null, dbIsTrue);
73
+ }
74
+ });
75
+ } catch (error) {
76
+ cb(error, null);
77
+ }
78
+ }
79
+
80
+ initSequelize(val, cb) {
81
+ try {
82
+ const sq = new Sequelize({
83
+ dialect: val.dialect || "mysql",
84
+ host: val.host,
85
+ username: val.username,
86
+ password: val.password,
87
+ database: val.database,
88
+ port: val.port,
89
+ storage: val.storage || ":memory:",
90
+ protocol: val.protocol || null,
91
+ logging: val.logging || false,
92
+ dialectOptions: {
93
+ socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
94
+ supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
95
+ bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
96
+ options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
97
+ },
98
+ omitNull: val.omitNull || false,
99
+ native: val.native || false,
100
+ define: {
101
+ underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
102
+ freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
103
+ charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
104
+ dialectOptions: {
105
+ collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
106
+ },
107
+ timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
108
+ },
109
+ sync: {
110
+ force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
111
+ },
112
+ pool: {
113
+ max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
114
+ idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
115
+ acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
116
+ },
117
+ isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
118
+ query: {
119
+ raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
120
+ nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
121
+ }
122
+ });
123
+ cb(false, sq);
124
+ } catch (error) {
125
+ cb(error, null);
126
+ }
127
+ }
128
+
129
+ testConnectInProcess = (database_config, dbConnTotal, cb) => {
130
+ try {
131
+ let val = database_config.shift();
132
+ if (val) {
133
+ this.initSequelize(val, async (err, sq) => {
134
+ if (err) {
135
+ console.error(" Failed  Can't to create a Sequelize instance:", val.name, "\n", err);
136
+ cb(err, null, null);
137
+ }
138
+ // Test connection
139
+ await sq.authenticate()
140
+ .then(() => {
141
+ // Database some is true perfectly.
142
+ if (database_config.length == 0) {
143
+ if (sq) {
144
+ testSql[ val.name ] = sq;
145
+ //console.log("DB true, Perfectly.", val.name);
146
+ cb(null, true, testSql);
147
+ }
148
+ } else {
149
+ testSql[ val.name ] = sq;
150
+ this.testConnectInProcess(database_config, dbConnTotal, cb);
151
+ }
152
+ })
153
+ .catch(err => {
154
+ console.error(" Failed  Unable to connect to the database:", val.name, "\n", err);
155
+ cb(err, null, null);
156
+ });
157
+ });
158
+ } else if (!dbConnTotal) {
159
+ // All Database is falsly perfectly.
160
+ //console.log("DB all false, Perfectly.");
161
+ cb(null, true, testSql);
162
+ }
163
+ } catch (error) {
164
+ cb(error, null, null);
165
+ }
166
+ }
167
+
168
+ getStart(turnNoti, cb) {
169
+ try {
170
+ clear();
171
+ logUpdate("Compiling...");
172
+ // filter for check dabatase only true
173
+ this.filterDbIsTrue(this._config_.database_config, (err, dbConnectIsTrueOnly) => {
174
+ if (err) {
175
+ logUpdate("Config file crash.", err);
176
+ return;
177
+ }
178
+ // leave data to disconnect database
179
+ let leaveDataForDisconnect = dbConnectIsTrueOnly.slice(0);
180
+ // check db connect truthy length ?
181
+ if (dbConnectIsTrueOnly.length > 0) {
182
+ // Test connect process
183
+ this.testConnectInProcess(dbConnectIsTrueOnly, dbConnectIsTrueOnly.length, (err, result, dbs) => {
184
+ if (err) {
185
+ logUpdate(" Failed  Database connect failed.", err);
186
+ return;
187
+ }
188
+ if (result) {
189
+ // Disconnect database
190
+ this.disConnectTestDB(leaveDataForDisconnect, dbs, (err, disResult) => {
191
+ if (err) {
192
+ logUpdate(" Failed  Testing Database connect failed.", err);
193
+ return;
194
+ }
195
+ if (disResult) {
196
+ // Start service
197
+ this.serviceDevStart();
198
+ // check turn on nofi
199
+ if (turnNoti) {
200
+ this.notiCompile();
201
+ }
202
+ } else {
203
+ cb(err, null);
204
+ }
205
+ });
206
+ }
207
+ });
208
+ } else {
209
+ this.serviceDevStart();
210
+ }
211
+ });
212
+ } catch (error) {
213
+ cb(error, null);
214
+ }
215
+ }
216
+
217
+ serviceDevStart() {
218
+ let firstCount = 0;
219
+ const command = this.cmd.get(`npx nodemon -q ./node_modules/beech-api/packages/cli/beech`);
220
+ command.stdout.on('data', (data) => {
221
+ firstCount++;
222
+ let leaveData = data.slice(0);
223
+ if (firstCount == 1) {
224
+ clear();
225
+ }
226
+ // shout out
227
+ if (data.trim().slice(-1) == ":") {
228
+ console.log("\n", leaveData.trim());
229
+ } else {
230
+ let serviceShoutOut = leaveData.trim().split('- ');
231
+ if (serviceShoutOut.length > 2) {
232
+ console.log(" -", serviceShoutOut[ 1 ].trim());
233
+ console.log(" -", serviceShoutOut[ 2 ].trim());
234
+ } else {
235
+ console.log(" ", leaveData.trim());
236
+ }
237
+ }
238
+
239
+ });
240
+ }
241
+
242
+ notiCompile() {
243
+ notifier.notify({
244
+ title: 'Beech API',
245
+ subtitle: 'Beech service getting started.',
246
+ message: "Service getting started.",
247
+ sound: 'Funk',
248
+ wait: false,
249
+ icon: path.join(__dirname, "/../../public/icon/beech_128.png"),
250
+ contentImage: path.join(__dirname, "../../public/icon/beech_128.png"),
251
+ });
252
+ }
253
+
254
+ disConnectTestDB(dbConfigTruthy, dbs, cb) {
255
+ try {
256
+ dbConfigTruthy.map((e, k) => {
257
+ // Closing database
258
+ if (dbs[ e.name ].close()) {
259
+ if (dbConfigTruthy.length == k + 1) {
260
+ cb(null, dbConfigTruthy);
261
+ }
262
+ } else {
263
+ cb(`Close database failed, ${e.name}`, null);
264
+ }
265
+ });
266
+ } catch (error) {
267
+ cb(error, null);
268
+ }
269
+ }
270
+
271
+ help() {
272
+ return new Promise((resolve, reject) => {
273
+ try {
274
+ this.fs.readFile(__dirname + "/../core/generator/_service", "utf8", (err, data) => {
275
+ if (err) {
276
+ reject(err);
277
+ } else {
278
+ resolve(data);
279
+ }
280
+ });
281
+ } catch (error) {
282
+ reject(error);
283
+ }
284
+ });
285
+ }
286
+
287
+ embed(argv) {
288
+ return new Promise((resolve, reject) => {
289
+ try {
290
+ this.fs = require("fs");
291
+ this.cmd = require('node-cmd');
292
+ this.argv = argv;
293
+ this.option = argv[ 2 ];
294
+ this.argument = argv[ 3 ];
295
+ this.configFile = path.resolve("./app.config.js");
296
+ this._config_ = require(this.configFile);
297
+ resolve(this);
298
+ } catch (error) {
299
+ reject(error);
300
+ }
301
+ });
302
+ }
303
+ }
304
+
305
+ new Beech();
@@ -141,23 +141,27 @@ class Beech {
141
141
  let tmpBasicHelperFile = __dirname + '/../core/generator/_basic-helpers';
142
142
  let pasteBasicHelperFile = helperPath + '/Basic.js';
143
143
  let freatureLength = freatureArr.length;
144
- freatureArr.map((f, key) => {
145
- if (f.split(' ')[ 0 ] == "Add-Ons") {
146
- (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech.js add-on init') : this.cmd.get('cd ' + argument + ' && beech add-on init');
147
- console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Add-Ons");
148
- }
149
- if (f.split(' ')[ 0 ] == "Basic") {
150
- this.makeFolder(helperPath).then(this.copy.bind(this, tmpBasicHelperFile, pasteBasicHelperFile))
151
- console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Basic helper");
152
- }
153
- if (f.split(' ')[ 0 ] == "Passport") {
154
- (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech.js passport init') : this.cmd.get('cd ' + argument + ' && beech passport init');
155
- console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Passport JWT, Official strategy Google, Facebook");
156
- }
157
- if (freatureArr.length == (key + 1)) {
158
- resolve(true);
159
- }
160
- });
144
+ if (freatureLength) {
145
+ freatureArr.map((f, key) => {
146
+ if (f.split(' ')[ 0 ] == "Add-Ons") {
147
+ (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech.js add-on init') : this.cmd.get('cd ' + argument + ' && beech add-on init');
148
+ console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Add-Ons");
149
+ }
150
+ if (f.split(' ')[ 0 ] == "Basic") {
151
+ this.makeFolder(helperPath).then(this.copy.bind(this, tmpBasicHelperFile, pasteBasicHelperFile))
152
+ console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Basic helper");
153
+ }
154
+ if (f.split(' ')[ 0 ] == "Passport") {
155
+ (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech.js passport init') : this.cmd.get('cd ' + argument + ' && beech passport init');
156
+ console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Passport JWT, Official strategy Google, Facebook");
157
+ }
158
+ if (freatureArr.length == (key + 1)) {
159
+ resolve(true);
160
+ }
161
+ });
162
+ } else {
163
+ resolve(true);
164
+ }
161
165
  } catch (error) {
162
166
  reject(error);
163
167
  }
@@ -154,6 +154,10 @@ module.exports = {
154
154
  callbackURL: auth_endpoint + facebook_callbackURL,
155
155
  profileFields: allow_permisions_fields
156
156
  }, (accessToken, refreshToken, profile, done) => {
157
+ // Check if the email permission is granted
158
+ if (!profile.emails || profile.emails.length === 0) {
159
+ return done(new Error('Email permission not granted.'));
160
+ }
157
161
  // find facebook user
158
162
  let faecbookIdField = (passport_config.strategy.facebook.local_profile_fields.facebook_id) ? passport_config.strategy.facebook.local_profile_fields.facebook_id : "facebook_id";
159
163
  this.findOrCreate(passport_config, "facebook", passportFields, passportTable, accessToken, refreshToken, profile, faecbookIdField, (err, res, dbFailed) => {
@@ -78,6 +78,11 @@ module.exports = {
78
78
  collate: "utf8_general_ci"
79
79
  },
80
80
  },
81
+ dialectOptions: { // ssl
82
+ options: {
83
+ encrypt: false,
84
+ }
85
+ },
81
86
  is_connect: false,
82
87
  },
83
88
  ]
@@ -52,6 +52,7 @@ connectInProcess = async (database_config, headDbShow, cb) => {
52
52
  socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
53
53
  supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
54
54
  bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
55
+ options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
55
56
  },
56
57
 
57
58
  // disable inserting undefined values as NULL
@@ -95,28 +96,29 @@ connectInProcess = async (database_config, headDbShow, cb) => {
95
96
  // isolation level of each transaction
96
97
  // defaults to dialect default
97
98
  isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
98
-
99
+
99
100
  // JSON response
100
101
  query: {
101
102
  raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
102
- nest : ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
103
+ nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
103
104
  }
104
105
  });
105
- // show only one text db connnections
106
- if (headDbShow) {
107
- console.log('\n Passed  Database is connected at:');
108
- headDbShow = false;
109
- }
106
+
110
107
  // connection
111
108
  await sq.authenticate()
112
109
  .then(() => {
110
+ // show only one text db connnections
111
+ if (headDbShow) {
112
+ console.log('\n Passed  Database is connected at:');
113
+ headDbShow = false;
114
+ }
113
115
  // create database pool
114
116
  sql[ val.name ] = sq;
115
117
  // checking dialect sql
116
- if(val.dialect == "sqlite") {
117
- console.log(' - [' + val.dialect + '] ' + val.name + ' -> ' + sq.options.storage + '');
118
+ if (val.dialect == "sqlite") {
119
+ console.log('- [' + val.dialect + '] ' + val.name + ' -> ' + sq.options.storage + '');
118
120
  } else {
119
- console.log(' - [' + val.dialect + '] ' + val.name + ' -> ' + sq.config.database + ':' + sq.config.port + '');
121
+ console.log('- [' + val.dialect + '] ' + val.name + ' -> ' + sq.config.database + ':' + sq.config.port + '');
120
122
  }
121
123
  // checking recursive database connection
122
124
  if (database_config.length > 0) {
@@ -4,11 +4,11 @@
4
4
  "description": "The project is powered by Beech API framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "start": "npx run ./node_modules/beech-api/packages/cli/beech",
7
+ "start": "beech-service serve",
8
8
  "test": "node ./node_modules/jest/bin/jest __tests__ -o --watch --config"
9
9
  },
10
10
  "dependencies": {
11
- "beech-api": "^3.5.7"
11
+ "beech-api": "^3.5.12"
12
12
  },
13
13
  "devDependencies": {
14
14
  "jest": "^25.2.7"
@@ -0,0 +1,8 @@
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.
@@ -77,10 +77,11 @@ walker.on("end", () => {
77
77
  init = async (jsfiles) => {
78
78
  try {
79
79
  await ((pool_base == "basic") ? new Promise((resolve) => resolve(mySqlDbConnect.connect())) : new Promise((resolve) => resolve(SequelizeDbConnect.connect())));
80
- await new Promise((resolve) => resolve(httpExpress.expressStart()));
81
80
  await new Promise((resolve) => resolve(authPassport.init()));
82
81
  await new Promise((resolve) => resolve(fileWalk.fileWalk(jsfiles)));
82
+ await new Promise((resolve) => resolve(httpExpress.expressStart()));
83
83
  } catch (error) {
84
+ console.log(" Compile failed ", error);
84
85
  throw error;
85
86
  }
86
87
  }
@@ -10,8 +10,10 @@ module.exports = {
10
10
  try {
11
11
  // Create express server
12
12
  const ExpressServer = _app_.listen(_config_.main_config.app_port, async () => {
13
- await console.log('\n Passed  Service is started at:\n - Local: http://' + _config_.main_config.app_host + ':' + ExpressServer.address().port, '\n - Network: ' + _config_.main_config.client_host + '');
14
- await this.authentication();
13
+ console.log(' Passed  Service is started at:');
14
+ console.log('- Local: http://' + _config_.main_config.app_host + ':' + ExpressServer.address().port + '');
15
+ console.log('- Network: ' + _config_.main_config.client_host + '');
16
+ this.authentication();
15
17
  await this.badRequest()
16
18
  .then(resolve(ExpressServer))
17
19
  .catch(err => {
@@ -62,16 +64,16 @@ module.exports = {
62
64
  var Beech = require("../../../lib/beech");
63
65
  if (!passport_config.jwt_allow) {
64
66
  // jwt is false
65
- console.log(" - JWT: OFF");
67
+ console.log("- JWT: OFF");
66
68
  return;
67
69
  }
68
70
  // jwt is true
69
- console.log(" - JWT: ON");
71
+ console.log("- JWT: ON");
70
72
  } else {
71
73
  return;
72
74
  }
73
75
  // declare authentication endpoint name
74
- const auth_endpoint = (passport_config.auth_endpoint) ? (passport_config.auth_endpoint[0] === "/" ? passport_config.auth_endpoint : "/" + passport_config.auth_endpoint) : "/authentication";
76
+ const auth_endpoint = (passport_config.auth_endpoint) ? (passport_config.auth_endpoint[ 0 ] === "/" ? passport_config.auth_endpoint : "/" + passport_config.auth_endpoint) : "/authentication";
75
77
  // authentication endpoints
76
78
  _app_.post(auth_endpoint, (req, res, next) => {
77
79
  passport.authenticate('local', { session: false }, (err, user, opt) => {
@@ -86,7 +88,7 @@ module.exports = {
86
88
  const accessToken = jwt.sign(user, passport_config.secret, {
87
89
  expiresIn: passport_config.token_expired
88
90
  });
89
- if (passport_config.app_secret_allow) {
91
+ if (passport_config.app_secret_allow) {
90
92
  if (req.body.app_secret) {
91
93
  if (_config_.main_config.app_secret == req.body.app_secret) {
92
94
  res.status(200).json({
@@ -151,7 +153,7 @@ module.exports = {
151
153
  ]
152
154
  }));
153
155
  // google auth callback
154
- const googleCallback = (passport_config.strategy.google.callbackURL) ? (passport_config.strategy.google.callbackURL[0] === "/" ? passport_config.strategy.google.callbackURL : "/" + passport_config.strategy.google.callbackURL) : "/google/callback";
156
+ const googleCallback = (passport_config.strategy.google.callbackURL) ? (passport_config.strategy.google.callbackURL[ 0 ] === "/" ? passport_config.strategy.google.callbackURL : "/" + passport_config.strategy.google.callbackURL) : "/google/callback";
155
157
  _app_.get(auth_endpoint + googleCallback, passport.authenticate('google', { failureRedirect: passport_config.strategy.google.failureRedirect, failureMessage: true }), (req, res) => {
156
158
  if (typeof req.user.user !== 'undefined') {
157
159
  // declare user for sign JWT
@@ -169,7 +171,7 @@ module.exports = {
169
171
  });
170
172
  } else {
171
173
  let condUser = {};
172
- condUser[(passport_config.strategy.google.local_profile_fields.google_id) ? passport_config.strategy.google.local_profile_fields.google_id : "google_id"] = req.user.google.id;
174
+ condUser[ (passport_config.strategy.google.local_profile_fields.google_id) ? passport_config.strategy.google.local_profile_fields.google_id : "google_id" ] = req.user.google.id;
173
175
  Beech.findOne([], condUser, (err, result) => {
174
176
  if (err) {
175
177
  res.status(500).json({
@@ -179,7 +181,7 @@ module.exports = {
179
181
  error: err
180
182
  });
181
183
  } else {
182
- let user = JSON.parse(JSON.stringify(result[0]));
184
+ let user = JSON.parse(JSON.stringify(result[ 0 ]));
183
185
  const accessToken = jwt.sign(user, passport_config.secret, {
184
186
  expiresIn: passport_config.token_expired
185
187
  });
@@ -204,9 +206,9 @@ module.exports = {
204
206
  *
205
207
  */
206
208
  if (passport_config.strategy.facebook.allow) {
207
- _app_.get(auth_endpoint + '/facebook', passport.authenticate('facebook', { scope: ['email', 'pages_show_list'] }));
209
+ _app_.get(auth_endpoint + '/facebook', passport.authenticate('facebook', { scope: [ 'email', 'public_profile' ] }));
208
210
  // facebook callback
209
- const facebookCallback = (passport_config.strategy.facebook.callbackURL) ? (passport_config.strategy.facebook.callbackURL[0] === "/" ? passport_config.strategy.facebook.callbackURL : "/" + passport_config.strategy.facebook.callbackURL) : "/facebook/callback";
211
+ const facebookCallback = (passport_config.strategy.facebook.callbackURL) ? (passport_config.strategy.facebook.callbackURL[ 0 ] === "/" ? passport_config.strategy.facebook.callbackURL : "/" + passport_config.strategy.facebook.callbackURL) : "/facebook/callback";
210
212
  _app_.get(auth_endpoint + facebookCallback, passport.authenticate('facebook', { failureRedirect: passport_config.strategy.facebook.failureRedirect, failureMessage: true }), (req, res) => {
211
213
  if (typeof req.user.user !== 'undefined') {
212
214
  // declare user for sign JWT
@@ -224,7 +226,7 @@ module.exports = {
224
226
  });
225
227
  } else {
226
228
  let condUser = {};
227
- condUser[(passport_config.strategy.facebook.local_profile_fields.facebook_id) ? passport_config.strategy.facebook.local_profile_fields.facebook_id : "facebook_id"] = req.user.facebook.id;
229
+ condUser[ (passport_config.strategy.facebook.local_profile_fields.facebook_id) ? passport_config.strategy.facebook.local_profile_fields.facebook_id : "facebook_id" ] = req.user.facebook.id;
228
230
  Beech.findOne([], condUser, (err, result) => {
229
231
  if (err) {
230
232
  res.status(500).json({
@@ -234,7 +236,7 @@ module.exports = {
234
236
  error: err
235
237
  });
236
238
  } else {
237
- let user = JSON.parse(JSON.stringify(result[0]));
239
+ let user = JSON.parse(JSON.stringify(result[ 0 ]));
238
240
  const accessToken = jwt.sign(user, passport_config.secret, {
239
241
  expiresIn: passport_config.token_expired
240
242
  });
@@ -8,7 +8,8 @@
8
8
  "test": "node ./node_modules/jest/bin/jest __tests__ -o --watch --config"
9
9
  },
10
10
  "dependencies": {
11
- "beech-api": "^3.5.5",
11
+ "beech-api": "^3.5.11",
12
+ "nodemon": "^3.0.1",
12
13
  "sqlite3": "^5.0.11",
13
14
  "tedious": "^15.0.1"
14
15
  },
@@ -0,0 +1,9 @@
1
+ //const Users = require("@/models/Users");
2
+
3
+ exports.init = () => {
4
+
5
+ //Users.findAll().then(console.log)
6
+
7
+ console.log("Add-on is work!")
8
+
9
+ }
@@ -0,0 +1,118 @@
1
+ const Beech = require("../../lib/beech");
2
+ const Users = require("@/models/Users");
3
+ const Users2 = require("@/models/Users-sqlite");
4
+ const User2Sequelize = require("@/models/User2Sequelize");
5
+ const Map_master = require("@/models/Map_master");
6
+
7
+ exports.init = () => {
8
+ // Initiate with basic request currently support GET, POST, PUT, PATCH and DELETE
9
+
10
+ /@GET/
11
+ endpoint.get('/hello', Credentials, async (req, res) => {
12
+ // basic get method
13
+ let data = {};
14
+ data.code = 200;
15
+ data.message = 'Got a GET request.';
16
+
17
+ /* await Users.findAll().then(e=> {
18
+ data.results = e
19
+ }); */
20
+
21
+ let fields = {
22
+ username: "eiei",
23
+ password: "xxx",
24
+ email: "bomb@bomb.com",
25
+ name: "jubu eiei"
26
+ }
27
+
28
+
29
+ /* Beech.store(fields, (err, result) => {
30
+ if(err) {
31
+ console.log(err);
32
+ } else {
33
+ console.log(result);
34
+ }
35
+ }); */
36
+
37
+ /* await Beech.findOne([], { id: 66 }, (err, result) => {
38
+ data.result = result
39
+ }) */
40
+
41
+ /* Beech.update({ username: "eiei", name: 'eiei222' }, 69, (err, result) => {
42
+ console.log(result);
43
+ }) */
44
+
45
+ data.result = await Users2.findAll(); // basic
46
+ //data.results = await User2Sequelize.findAll(); // sequelize
47
+ //data.results = await User2Sequelize.findUser2SequelizeById(7) // sequelize
48
+
49
+ //data.results = await Map_master.findAll() // sequelize
50
+
51
+
52
+
53
+
54
+
55
+ // @return
56
+ res.json(data);
57
+ });
58
+
59
+ /@POST/
60
+ endpoint.post('/hello', Credentials, (req, res) => {
61
+ /**
62
+ * @param Integer id
63
+ *
64
+ * @return json
65
+ */
66
+ let id = req.body.id;
67
+ let data = {};
68
+ data.code = 200;
69
+ data.message = 'Got a POST request.';
70
+ // @return
71
+ res.json(data);
72
+ });
73
+
74
+ /@PUT/
75
+ endpoint.put('/hello/:id', Credentials, (req, res) => {
76
+ /**
77
+ * @param Integer id
78
+ *
79
+ * @return json
80
+ */
81
+ let id = req.params.id;
82
+ let data = {};
83
+ data.code = 200;
84
+ data.message = 'Got a PUT request at /hello/' + id;
85
+ // @return
86
+ res.json(data);
87
+ });
88
+
89
+ /@PATCH/
90
+ endpoint.patch('/hello/:id', Credentials, (req, res) => {
91
+ /**
92
+ * @param Integer id
93
+ *
94
+ * @return json
95
+ */
96
+ let id = req.params.id;
97
+ let data = {};
98
+ data.code = 200;
99
+ data.message = 'Got a PATCH request at /hello/' + id;
100
+ // @return
101
+ res.json(data);
102
+ });
103
+
104
+ /@DELETE/
105
+ endpoint.delete('/hello/:id', Credentials, (req, res) => {
106
+ /**
107
+ * @param Integer id
108
+ *
109
+ * @return json
110
+ */
111
+ let id = req.params.id;
112
+ let data = {};
113
+ data.code = 200;
114
+ data.message = 'Got a DELETE request at /hello/' + id;
115
+ // @return
116
+ res.json(data);
117
+ });
118
+ }
@@ -0,0 +1,75 @@
1
+ // You can require something
2
+
3
+ exports.init = () => {
4
+ // Initiate with basic request currently support GET, POST, PUT, PATCH and DELETE
5
+
6
+ /@GET/
7
+ endpoint.get('/test2', Credentials, (req, res) => {
8
+ // basic get method
9
+ let data = {};
10
+ data.code = 200;
11
+ data.message = 'Got a GET request.';
12
+ // @return
13
+ res.json(data);
14
+ });
15
+
16
+ /@POST/
17
+ endpoint.post('/test2', Credentials, (req, res) => {
18
+ /**
19
+ * @param Integer id
20
+ *
21
+ * @return json
22
+ */
23
+ let id = req.body.id;
24
+ let data = {};
25
+ data.code = 200;
26
+ data.message = 'Got a POST request.';
27
+ // @return
28
+ res.json(data);
29
+ });
30
+
31
+ /@PUT/
32
+ endpoint.put('/test2/:id', Credentials, (req, res) => {
33
+ /**
34
+ * @param Integer id
35
+ *
36
+ * @return json
37
+ */
38
+ let id = req.params.id;
39
+ let data = {};
40
+ data.code = 200;
41
+ data.message = 'Got a PUT request at /test2/' + id;
42
+ // @return
43
+ res.json(data);
44
+ });
45
+
46
+ /@PATCH/
47
+ endpoint.patch('/test2/:id', Credentials, (req, res) => {
48
+ /**
49
+ * @param Integer id
50
+ *
51
+ * @return json
52
+ */
53
+ let id = req.params.id;
54
+ let data = {};
55
+ data.code = 200;
56
+ data.message = 'Got a PATCH request at /test2/' + id;
57
+ // @return
58
+ res.json(data);
59
+ });
60
+
61
+ /@DELETE/
62
+ endpoint.delete('/test2/:id', Credentials, (req, res) => {
63
+ /**
64
+ * @param Integer id
65
+ *
66
+ * @return json
67
+ */
68
+ let id = req.params.id;
69
+ let data = {};
70
+ data.code = 200;
71
+ data.message = 'Got a DELETE request at /test2/' + id;
72
+ // @return
73
+ res.json(data);
74
+ });
75
+ }
@@ -0,0 +1,23 @@
1
+ const Users = require("@/models/Users");
2
+ const Test = require("@/models/Test");
3
+
4
+ exports.init = () => {
5
+ // Initiate with basic request currently support GET, POST, PUT, PATCH and DELETE
6
+
7
+ /@GET/
8
+ endpoint.get('/testSequalize', Credentials, async (req, res) => {
9
+
10
+ let data = {};
11
+ data.code = 200;
12
+
13
+ data.results = await Users.getData();
14
+
15
+ data.resultTest = await Test.getData();
16
+
17
+ // @return
18
+ res.json(data);
19
+ });
20
+
21
+
22
+
23
+ }
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+
3
+ // textUpperCase(text) {
4
+ // return text.toUpperCase();
5
+ // },
6
+
7
+ // textTrim(text) {
8
+ // return text.trim();
9
+ // },
10
+
11
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+
3
+ // textUpperCase(text) {
4
+ // return text.toUpperCase();
5
+ // },
6
+
7
+ // textTrim(text) {
8
+ // return text.trim();
9
+ // },
10
+
11
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+
3
+ // textUpperCase(text) {
4
+ // return text.toUpperCase();
5
+ // },
6
+
7
+ // textTrim(text) {
8
+ // return text.trim();
9
+ // },
10
+
11
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+
3
+ // textUpperCase(text) {
4
+ // return text.toUpperCase();
5
+ // },
6
+
7
+ // textTrim(text) {
8
+ // return text.trim();
9
+ // },
10
+
11
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+
3
+ // textUpperCase(text) {
4
+ // return text.toUpperCase();
5
+ // },
6
+
7
+ // textTrim(text) {
8
+ // return text.trim();
9
+ // },
10
+
11
+ };
@@ -0,0 +1,29 @@
1
+ const data = [
2
+ { "id": 1, "name": "Oggy" },
3
+ { "id": 2, "name": "Jack" },
4
+ { "id": 3, "name": "The Cockroaches Gang" }
5
+ ];
6
+
7
+ module.exports = {
8
+
9
+ // Example basic function get constant data
10
+ getData() {
11
+ return data;
12
+ },
13
+
14
+ // Example basic function get data from Database (must be return promise)
15
+ findAll() {
16
+ return new Promise((resolve, reject) => {
17
+ try {
18
+ // call mysql `default_db` connection
19
+ mysql.default_db.query("SELECT * FROM jubu", (err, results) => {
20
+ if (err) { reject(err) }
21
+ resolve(results);
22
+ });
23
+ } catch (error) {
24
+ reject(error);
25
+ }
26
+ });
27
+ }
28
+
29
+ }
@@ -0,0 +1,20 @@
1
+ // You can asign datatype see more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
2
+ const Jubu2 = sql.default_db.define("jubu2", {
3
+ id: DataTypes.INTEGER,
4
+ examField1: DataTypes.STRING,
5
+ examField2: DataTypes.DATE,
6
+ });
7
+
8
+ module.exports = {
9
+
10
+ // Example basic function get one constant data
11
+ async getJubu2ById(id) {
12
+ return await Jubu2.findOne({ where: { id: id } });
13
+ },
14
+
15
+ // Example basic function get all data from Database (must be return promise)
16
+ async findAll() {
17
+ return await Jubu2.findAll();
18
+ }
19
+
20
+ }
@@ -0,0 +1,22 @@
1
+ // You can asign datatype see more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
2
+ const Map_master = sql.mysql_first_db.define("map_master", {
3
+ id: {
4
+ type: DataTypes.INTEGER,
5
+ autoIncrement: true,
6
+ primaryKey: true
7
+ },
8
+ });
9
+
10
+ module.exports = {
11
+
12
+ // Example basic function get one constant data
13
+ async findMap_masterById(id) {
14
+ return await Map_master.findOne({ where: { id: id } });
15
+ },
16
+
17
+ // Example basic function get all data from Database (must be return promise)
18
+ async findAll() {
19
+ return await Map_master.findAll();
20
+ }
21
+
22
+ }
@@ -0,0 +1,29 @@
1
+ const data = [
2
+ { "id": 1, "name": "Oggy" },
3
+ { "id": 2, "name": "Jack" },
4
+ { "id": 3, "name": "The Cockroaches Gang" }
5
+ ];
6
+
7
+ module.exports = {
8
+
9
+ // Example basic function get constant data
10
+ getData() {
11
+ return data;
12
+ },
13
+
14
+ // Example basic function get data from MySQL (must be return promise)
15
+ findAll() {
16
+ return new Promise((resolve, reject) => {
17
+ try {
18
+ // call mysql `default_db` connection
19
+ mysql.default_db.query("SELECT * FROM test", (err, results) => {
20
+ if (err) { reject(err) }
21
+ resolve(results);
22
+ });
23
+ } catch (error) {
24
+ reject(error);
25
+ }
26
+ });
27
+ }
28
+
29
+ }
@@ -0,0 +1,29 @@
1
+ const data = [
2
+ { "id": 1, "name": "Oggy" },
3
+ { "id": 2, "name": "Jack" },
4
+ { "id": 3, "name": "The Cockroaches Gang" }
5
+ ];
6
+
7
+ module.exports = {
8
+
9
+ // Example basic function get constant data
10
+ getData() {
11
+ return data;
12
+ },
13
+
14
+ // Example basic function get data from MySQL (must be return promise)
15
+ findAll() {
16
+ return new Promise((resolve, reject) => {
17
+ try {
18
+ // call mysql `default_db` connection
19
+ mysql.default_db.query("SELECT * FROM test2", (err, results) => {
20
+ if (err) { reject(err) }
21
+ resolve(results);
22
+ });
23
+ } catch (error) {
24
+ reject(error);
25
+ }
26
+ });
27
+ }
28
+
29
+ }
@@ -0,0 +1,23 @@
1
+ // You can asign datatype see more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
2
+ const User2Sequelize = sql.mysql_first_db.define("users", {
3
+ id: {
4
+ type: DataTypes.INTEGER,
5
+ autoIncrement: true,
6
+ primaryKey: true
7
+ },
8
+ name: DataTypes.STRING,
9
+ });
10
+
11
+ module.exports = {
12
+
13
+ // Example basic function get one constant data
14
+ async findUser2SequelizeById(id) {
15
+ return await User2Sequelize.findOne({ where: { 'id': id } });
16
+ },
17
+
18
+ // Example basic function get all data from Database (must be return promise)
19
+ async findAll() {
20
+ return await User2Sequelize.findAll();
21
+ }
22
+
23
+ }
@@ -0,0 +1,21 @@
1
+ const Users = sql.sqlite_db.define("users", {
2
+ id: {
3
+ type: DataTypes.INTEGER,
4
+ autoIncrement: true,
5
+ primaryKey: true
6
+ },
7
+ });
8
+
9
+ module.exports = {
10
+
11
+ // Example basic function get one constant data
12
+ findUsersById(id) {
13
+ return Users.findOne({ where: { id: id } });
14
+ },
15
+
16
+ // Example basic function get all data from table users
17
+ findAll() {
18
+ return Users.findAll();
19
+ }
20
+
21
+ }
@@ -0,0 +1,53 @@
1
+ // You can asign datatype see more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
2
+ const Users = sql.mysql_first_db.define('users', {
3
+ id: {
4
+ type: DataTypes.INTEGER,
5
+ autoIncrement: true,
6
+ primaryKey: true
7
+ },
8
+ username: DataTypes.STRING,
9
+ password: {
10
+ type: DataTypes.STRING,
11
+ set(value) {
12
+ // Storing passwords in plaintext in the database is terrible.
13
+ // Hashing the value with an appropriate cryptographic hash function is better.
14
+ this.setDataValue('password', hash(value));
15
+ }
16
+ },
17
+ name: DataTypes.STRING,
18
+ });
19
+
20
+
21
+
22
+ module.exports = {
23
+
24
+ // Example basic function get constant data
25
+ getData() {
26
+ let user = Users.findAll();
27
+ //console.log(user);
28
+ return user;
29
+ },
30
+
31
+ // Example basic function get data from MySQL (must be return promise)
32
+ findAll() {
33
+ return new Promise(async (resolve, reject) => {
34
+ try {
35
+
36
+ let raw = await sql.default_db.query("SELECT * FROM users LIMIT 1", { type: QueryTypes.SELECT }); // mysql
37
+ //let raw = await sql.second_db.query("SELECT * FROM usercon LIMIT 10"); // sqlite
38
+ // let raw = await this.sql.thirdth_db.query("SELECT TOP 10 * FROM usercon"); // mssql
39
+
40
+ //console.log(sql);
41
+
42
+
43
+ resolve(raw);
44
+
45
+
46
+
47
+ } catch (error) {
48
+ reject(error);
49
+ }
50
+ });
51
+ }
52
+
53
+ }
@@ -0,0 +1,23 @@
1
+ const Uuuuuxxx = sql.second_db.define("uuuuuxxx", {
2
+ id: {
3
+ type: DataTypes.INTEGER,
4
+ autoIncrement: true,
5
+ primaryKey: true,
6
+ },
7
+ examField1: DataTypes.STRING, // asign more DataTypes see more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
8
+ examField2: DataTypes.DATE,
9
+ });
10
+
11
+ module.exports = {
12
+
13
+ // Example basic function get one by id
14
+ findUuuuuxxxById(id) {
15
+ return Uuuuuxxx.findOne({ where: { id: id } });
16
+ },
17
+
18
+ // Example basic function get all data from table uuuuuxxx
19
+ findAll() {
20
+ return Uuuuuxxx.findAll();
21
+ }
22
+
23
+ }
@@ -0,0 +1,23 @@
1
+ const Uuuuuxxx = sql.second_db.define("uuuuuxxx", {
2
+ id: {
3
+ type: DataTypes.INTEGER,
4
+ autoIncrement: true,
5
+ primaryKey: true,
6
+ },
7
+ examField1: DataTypes.STRING, // asign more DataTypes see more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
8
+ examField2: DataTypes.DATE,
9
+ });
10
+
11
+ module.exports = {
12
+
13
+ // Example basic function get one by id
14
+ findUuuuuxxxById(id) {
15
+ return Uuuuuxxx.findOne({ where: { id: id } });
16
+ },
17
+
18
+ // Example basic function get all data from table uuuuuxxx
19
+ findAll() {
20
+ return Uuuuuxxx.findAll();
21
+ }
22
+
23
+ }