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.
Files changed (59) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1715 -1244
  3. package/index.js +2 -2
  4. package/package.json +92 -83
  5. package/packages/cli/beech +9 -10
  6. package/packages/cli/bin/beech-app.js +389 -389
  7. package/packages/cli/bin/beech-service.js +262 -132
  8. package/packages/cli/core/auth/Credentials.js +174 -147
  9. package/packages/cli/core/auth/Passport.js +664 -592
  10. package/packages/cli/core/auth/_Request.js +12 -12
  11. package/packages/cli/core/configure/_gitignore +16 -15
  12. package/packages/cli/core/configure/_sequelizerc +9 -9
  13. package/packages/cli/core/configure/app.config-basic.js +55 -55
  14. package/packages/cli/core/configure/app.config-sequelize.js +88 -88
  15. package/packages/cli/core/configure/beech.config.js +9 -9
  16. package/packages/cli/core/configure/global.config-basic.js +8 -8
  17. package/packages/cli/core/configure/global.config-sequelize.js +8 -8
  18. package/packages/cli/core/configure/jest.config.js +6 -6
  19. package/packages/cli/core/configure/jsconfig.json +8 -7
  20. package/packages/cli/core/configure/passport.config.js +97 -97
  21. package/packages/cli/core/databases/mysql.js +94 -95
  22. package/packages/cli/core/databases/sequelize.js +187 -179
  23. package/packages/cli/core/databases/test.js +251 -170
  24. package/packages/cli/core/file-walk/file-walk.js +35 -35
  25. package/packages/cli/core/generator/_endpoints +15 -15
  26. package/packages/cli/core/generator/_endpoints_basic +42 -42
  27. package/packages/cli/core/generator/_help +26 -18
  28. package/packages/cli/core/generator/_help_create +10 -10
  29. package/packages/cli/core/generator/_help_service +10 -10
  30. package/packages/cli/core/generator/_helpers +9 -9
  31. package/packages/cli/core/generator/_helpers_basic +22 -22
  32. package/packages/cli/core/generator/_models +6 -29
  33. package/packages/cli/core/generator/_models_basic +13 -22
  34. package/packages/cli/core/generator/_package +23 -20
  35. package/packages/cli/core/generator/_scheduler +32 -22
  36. package/packages/cli/core/generator/_spec +29 -29
  37. package/packages/cli/core/generator/index.js +1081 -738
  38. package/packages/cli/core/helpers/2fa.js +106 -85
  39. package/packages/cli/core/helpers/math.js +115 -103
  40. package/packages/cli/core/helpers/poolEntity.js +103 -59
  41. package/packages/cli/core/index.js +264 -188
  42. package/packages/cli/core/middleware/express/duplicateRequest.js +16 -12
  43. package/packages/cli/core/middleware/express/jwtCheckAllow.js +86 -68
  44. package/packages/cli/core/middleware/express/rateLimit.js +29 -17
  45. package/packages/cli/core/middleware/express/slowDown.js +2 -2
  46. package/packages/cli/core/middleware/index.js +6 -6
  47. package/packages/cli/core/middleware/origin/guard/advance.js +75 -74
  48. package/packages/cli/core/middleware/origin/whitelist/cors.js +94 -94
  49. package/packages/cli/core/services/http.express.js +481 -441
  50. package/packages/cli/core/test/check-node.js +21 -0
  51. package/packages/cli/core/test/utils.js +7 -7
  52. package/packages/cli/entry +10 -0
  53. package/packages/lib/index.js +6 -6
  54. package/packages/lib/src/endpoint.js +947 -532
  55. package/packages/lib/src/guard.js +60 -60
  56. package/packages/lib/src/salt.js +3 -3
  57. package/packages/lib/src/schema.js +96 -93
  58. package/packages/lib/src/specificExpress.js +7 -7
  59. package/packages/lib/src/user.js +271 -271
@@ -1,170 +1,251 @@
1
- const logUpdate = require("log-update");
2
- const emoji = require('node-emoji')
3
- const { DeHashIt, M, X } = require(__dirname + "/../helpers/math");
4
- const Sequelize = require('sequelize');
5
- let testSql = {};
6
-
7
- function filterDbIsTrue(dbConfig, cb) {
8
- try {
9
- let dbIsTrue = [];
10
- dbConfig.filter((e, k) => {
11
- if (e.is_connect) {
12
- dbIsTrue.push(e);
13
- }
14
- if (dbConfig.length == k + 1) {
15
- if(dbIsTrue.length) {
16
- console.log('\n Pre-Flight  Testing Database connection:');
17
- }
18
- setTimeout(() => {
19
- cb(null, dbIsTrue);
20
- }, 300);
21
- }
22
- });
23
- } catch (error) {
24
- cb(error, null);
25
- }
26
- }
27
-
28
- function testConnectInProcess (database_config, dbConnTotal, cb) {
29
- try {
30
- let val = database_config.shift();
31
- if (val) {
32
- initSequelize(val, async (err, sq) => {
33
- if (err) {
34
- console.error(" Failed  Can't connect to connection name:", val.name, "\n", err);
35
- cb(err, null, null);
36
- }
37
- // Test connection
38
- await sq.authenticate()
39
- .then(() => {
40
- // Database some is true perfectly.
41
- if (database_config.length == 0) {
42
- if (sq) {
43
- testSql[ val.name ] = sq;
44
- //console.log("DB true, Perfectly.", val.name);
45
- cb(null, true, testSql);
46
- }
47
- } else {
48
- testSql[ val.name ] = sq;
49
- testConnectInProcess(database_config, dbConnTotal, cb);
50
- }
51
- })
52
- .catch(err => {
53
- console.error(" Failed  Unable to connect to the database:", val.name, "\n", err);
54
- cb(err, null, null);
55
- });
56
- });
57
- } else if (!dbConnTotal) {
58
- // All Database is falsly perfectly.
59
- //console.log("DB all false, Perfectly.");
60
- cb(null, true, testSql);
61
- }
62
- } catch (error) {
63
- cb(error, null, null);
64
- }
65
- }
66
-
67
- function disConnectTestDB(dbConfigTruthy, dbs, cb) {
68
- try {
69
- dbConfigTruthy.map((e, k) => {
70
- // Closing database
71
- if (dbs[ e.name ].close()) {
72
- if (dbConfigTruthy.length == k + 1) {
73
- cb(null, dbConfigTruthy);
74
- }
75
- } else {
76
- cb(`Close database failed, ${e.name}`, null);
77
- }
78
- });
79
- } catch (error) {
80
- cb(error, null);
81
- }
82
- }
83
-
84
- function logit(msg, next = false) {
85
- logUpdate(msg);
86
- if(next) {
87
- logUpdate.done();
88
- }
89
- }
90
-
91
- function initSequelize(val, cb) {
92
- try {
93
- const promise = new Promise((resolve) => {
94
- // check hash ?
95
- if(val.username && val.password) {
96
- if(val.username.length < 55 || val.password < 55) {
97
- return cb("ERROR: No Hash access for connect to database.\n", null);
98
- }
99
- let accessDb = [];
100
- [val.username, val.password].map((e, k) => {
101
- DeHashIt(e.toString(), null, (17).toString().slice(0,-1).length, (err, d) => {
102
- if(!err) {
103
- accessDb.push(d.split("sh,")[1].split(M(X).toString().slice(0,2)+M(X).toString())[0].slice(0,-1));
104
- }
105
- });
106
- if(k+1==2) {
107
- resolve(accessDb);
108
- }
109
- });
110
- } else {
111
- resolve([null, null]);
112
- }
113
- });
114
- Promise.all([promise]).then(final => {
115
- // stdout pre-flight connection
116
- logit(`- [${val.dialect}] ${val.name}`);
117
- logit(emoji.get('heavy_multiplication_x') + ` [${val.dialect}] ${val.name}`);
118
- // create connection
119
- const sq = new Sequelize({
120
- dialect: val.dialect || "mysql",
121
- host: (val.host == "localhost" || val.host == "http://localhost") ? "127.0.0.1" : val.host,
122
- username: final[0][0],
123
- password: final[0][1],
124
- database: val.database,
125
- port: val.port,
126
- storage: val.storage || ":memory:",
127
- protocol: val.protocol || null,
128
- logging: val.logging || false,
129
- dialectOptions: {
130
- socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
131
- supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
132
- bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
133
- options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
134
- },
135
- omitNull: val.omitNull || false,
136
- native: val.native || false,
137
- define: {
138
- underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
139
- freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
140
- charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
141
- dialectOptions: {
142
- collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
143
- },
144
- timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
145
- },
146
- sync: {
147
- force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
148
- },
149
- pool: {
150
- max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
151
- idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
152
- acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
153
- },
154
- isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
155
- query: {
156
- raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
157
- nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
158
- }
159
- });
160
- logit(emoji.get('heavy_check_mark') + ` [${val.dialect}] ${val.name}`, true);
161
- cb(false, sq);
162
- }).catch(err => {
163
- console.log(` Warning  Connection name \`${val.name}\``, err);
164
- });
165
- } catch (error) {
166
- cb(error, null);
167
- }
168
- }
169
-
170
- module.exports = { filterDbIsTrue, testConnectInProcess, disConnectTestDB }
1
+ const logUpdate = require("log-update");
2
+ const { DeHashIt, M, X } = require(__dirname + "/../helpers/math");
3
+ const Sequelize = require('sequelize');
4
+ const fs = require("fs");
5
+ let testSql = {};
6
+
7
+ function filterDbIsTrue(dbConfig, cb) {
8
+ try {
9
+ let dbIsTrue = [];
10
+ dbConfig.filter((e, k) => {
11
+ if (e.is_connect) {
12
+ dbIsTrue.push(e);
13
+ }
14
+ if (dbConfig.length == k + 1) {
15
+ if(dbIsTrue.length) {
16
+ console.log('\n Pre-Flight  Testing Database connection:');
17
+ }
18
+ setTimeout(() => {
19
+ cb(null, dbIsTrue);
20
+ }, 200);
21
+ }
22
+ });
23
+ } catch (error) {
24
+ cb(error, null);
25
+ }
26
+ }
27
+
28
+ function testConnectInProcess(database_config, dbConnTotal, cb) {
29
+ try {
30
+ // Recursive test connection
31
+ let val = database_config.shift();
32
+ if (val) {
33
+ initSequelize(val, true, async (err, sq) => {
34
+ if (err) {
35
+ //console.log(" Failed  Can't connect to connection name:", val.name, "\n", err);
36
+ return cb(err, null, null);
37
+ } else {
38
+ // Test connection
39
+ await sq.authenticate()
40
+ .then(() => {
41
+ // Database some is true perfectly.
42
+ if (database_config.length == 0) {
43
+ if (sq) {
44
+ testSql[ val.name ] = sq;
45
+ //console.log("DB true, Perfectly.", val.name);
46
+ return cb(null, true, testSql);
47
+ }
48
+ } else {
49
+ testSql[ val.name ] = sq;
50
+ testConnectInProcess(database_config, dbConnTotal, cb);
51
+ }
52
+ })
53
+ .catch(err => {
54
+ logit(`[X] [${val.dialect}] ${val.name}`);
55
+ console.log(" Failed  Unable to connect to the database:", val.name, "\n", err);
56
+ return cb(err, null, null);
57
+ });
58
+ }
59
+ });
60
+ } else if (!dbConnTotal) {
61
+ // All Database is falsly perfectly.
62
+ //console.log("DB all false, Perfectly.");
63
+ return cb(null, true, testSql);
64
+ }
65
+ } catch (error) {
66
+ return cb(error, null, null);
67
+ }
68
+ }
69
+
70
+ function disConnectTestDB(dbConfigTruthy, dbs, cb) {
71
+ try {
72
+ dbConfigTruthy.map((e, k) => {
73
+ // Closing database
74
+ if (dbs[ e.name ].close()) {
75
+ if (dbConfigTruthy.length == k + 1) {
76
+ cb(null, dbConfigTruthy);
77
+ }
78
+ } else {
79
+ cb(`Close database failed, ${e.name}`, null);
80
+ }
81
+ });
82
+ } catch (error) {
83
+ cb(error, null);
84
+ }
85
+ }
86
+
87
+ function logit(msg, next = false) {
88
+ logUpdate(msg);
89
+ if(next) {
90
+ logUpdate.done();
91
+ }
92
+ }
93
+
94
+ function initSequelize(val, testConn = true, cb) {
95
+ try {
96
+ const promise = new Promise((resolve) => {
97
+ // check hash ?
98
+ if(val.username && val.password) {
99
+ if(val.username.length < 55 || val.password < 55) {
100
+ return cb("ERR: Incorrect Hash access for connect to database, Please Hashing your access by command `beech hash:<your_access>`\n", null);
101
+ }
102
+ let accessDb = [];
103
+ [val.username, val.password].forEach((e, k) => {
104
+ DeHashIt(e.toString(), null, (17).toString().slice(0,-1).length, (err, d) => {
105
+ if (err) {
106
+ return cb("Hash access error", err);
107
+ }
108
+ accessDb[k] = d.split("sh,")[1].split(M(X).toString().slice(0,2) + M(X).toString())[0].slice(0,-1);
109
+ if (accessDb[0] && accessDb[1]) {
110
+ accessDb[2] = val.dialect;
111
+ resolve(accessDb);
112
+ }
113
+ });
114
+ });
115
+ } else {
116
+ resolve([null, null]);
117
+ }
118
+ });
119
+ Promise.all([promise]).then(final => {
120
+ /**
121
+ * The final callback variable : [['hashed', 'hashed', 'dialect']]
122
+ *
123
+ * final[0][0] : username hashed
124
+ * final[0][1] : password hashed
125
+ * final[0][2] : dialect
126
+ *
127
+ */
128
+
129
+ // Check test connection for stdout pre-flight
130
+ if(testConn) {
131
+ // stdout pre-flight connection
132
+ logit(`[+] [${val.dialect}] ${val.name}`);
133
+ }
134
+ fs.readFile("./global.config.js", 'utf8', (err, data) => {
135
+ if (err) {
136
+ console.log("\n Fatal  Can't read `global.config.js` file.\n", err);
137
+ return; // break;
138
+ } else {
139
+ let buffer = Buffer.from(data);
140
+ let buf2str = buffer.toString();
141
+ let buf2json = JSON.parse(JSON.stringify(buf2str));
142
+ let pool_base = /global.pool_base\s+=\s+(?:"|')([^"]+)(?:"|')(?:\r|\n|$|;|\r)/i.exec(buf2json);
143
+ if (pool_base) {
144
+ if(pool_base == "basic") {
145
+ if(final[0][2] != "mysql") {
146
+ return cb(`The Basic pool engine not support with: ${val.dialect}, Please use Sequelize engine.`, null);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ });
152
+ // create connection
153
+ const sq = new Sequelize({
154
+ dialect: val.dialect || "mysql",
155
+ host: (val.host == "localhost" || val.host == "http://localhost") ? "127.0.0.1" : val.host,
156
+ username: final[0][0],
157
+ password: final[0][1],
158
+ database: val.database,
159
+ port: val.port,
160
+ storage: val.storage || ":memory:",
161
+ protocol: val.protocol || null,
162
+ logging: val.logging || false,
163
+ dialectOptions: {
164
+ socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
165
+ supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
166
+ bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
167
+ options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
168
+ },
169
+ omitNull: val.omitNull || false,
170
+ native: val.native || false,
171
+ define: {
172
+ underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
173
+ freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
174
+ charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
175
+ dialectOptions: {
176
+ collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
177
+ },
178
+ timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
179
+ },
180
+ sync: {
181
+ force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
182
+ },
183
+ pool: {
184
+ max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
185
+ idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
186
+ acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
187
+ },
188
+ isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
189
+ query: {
190
+ raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
191
+ nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
192
+ }
193
+ });
194
+ // Check test connection for stdout pre-flight (mark)
195
+ if(testConn) {
196
+ logit(`[/] [${val.dialect}] ${val.name}`, true);
197
+ }
198
+ cb(false, sq);
199
+ }).catch(err => {
200
+ console.log(` Warning  Connection name \`${val.name}\``, err);
201
+ });
202
+ } catch (error) {
203
+ cb(error, null);
204
+ }
205
+ }
206
+
207
+ function connectForGenerateModel(dbConnectName, tableName, databaseConfig, cb) {
208
+ /**
209
+ * Callback
210
+ *
211
+ * err String : Error message
212
+ * tableSchema Object : Schema of table
213
+ * tableName String : table name
214
+ *
215
+ */
216
+ const connectionChoose = databaseConfig.find(e => e.name === dbConnectName);
217
+ initSequelize(connectionChoose, false, async (err, sq) => {
218
+ if (err) {
219
+ return cb(err, null, null);
220
+ }
221
+ // Connection
222
+ await sq.authenticate()
223
+ .then(() => {
224
+ getTableSchema(sq, tableName, (errSchema, tableSchema) => {
225
+ if(errSchema) {
226
+ cb(errSchema, null, null);
227
+ } else {
228
+ // Closing database
229
+ sq.close();
230
+ // Callback
231
+ cb(null, tableSchema, tableName);
232
+ }
233
+ });
234
+ })
235
+ .catch(err => {
236
+ cb(err, null, null);
237
+ });
238
+ });
239
+ }
240
+
241
+ async function getTableSchema(sq, tableName, cb) {
242
+ try {
243
+ const queryInterface = sq.getQueryInterface();
244
+ const schema = await queryInterface.describeTable(tableName);
245
+ cb(null, schema);
246
+ } catch (error) {
247
+ cb("Fetching table schema " + error, null);
248
+ }
249
+ }
250
+
251
+ module.exports = { filterDbIsTrue, testConnectInProcess, disConnectTestDB, connectForGenerateModel }
@@ -1,35 +1,35 @@
1
- /**
2
- * file walk autoload all file
3
- *
4
- */
5
- exports.fileWalk = (files) => {
6
- return new Promise((resolve, reject) => {
7
- try {
8
- if (files.length) {
9
- let route;
10
- files.map((val, key) => {
11
- let endpointFile = val.replace(".js", "");
12
- try {
13
- route = require(endpointFile);
14
- if (route instanceof Error) {
15
- console.log(out.message);
16
- reject(error);
17
- }
18
- route.init();
19
- if (files.length == key + 1) {
20
- resolve(true);
21
- }
22
- } catch (error) {
23
- console.log(error);
24
- reject(error);
25
- }
26
- });
27
- } else {
28
- resolve(true);
29
- }
30
- } catch (error) {
31
- console.log(error);
32
- reject(error);
33
- }
34
- });
35
- };
1
+ /**
2
+ * file walk autoload all file
3
+ *
4
+ */
5
+ exports.fileWalk = (files) => {
6
+ return new Promise((resolve, reject) => {
7
+ try {
8
+ if (files.length) {
9
+ let route;
10
+ files.map((val, key) => {
11
+ let endpointFile = val.replace(".js", "");
12
+ try {
13
+ route = require(endpointFile);
14
+ if (route instanceof Error) {
15
+ console.log(out.message);
16
+ reject(error);
17
+ }
18
+ route.init();
19
+ if (files.length == key + 1) {
20
+ resolve(true);
21
+ }
22
+ } catch (error) {
23
+ console.log(error);
24
+ reject(error);
25
+ }
26
+ });
27
+ } else {
28
+ resolve(true);
29
+ }
30
+ } catch (error) {
31
+ console.log(error);
32
+ reject(error);
33
+ }
34
+ });
35
+ };
@@ -1,15 +1,15 @@
1
- {{requireSomething}}
2
- exports.init = () => {
3
- // GET request
4
- endpoint.get("/{{endpoint}}", Credentials, (req, res) => {
5
- // @response
6
- res.json({
7
- code: 200,
8
- status: "SUCCESS",
9
- message: "GET request at /{{endpoint}}",
10
- });
11
- });
12
-
13
- // Create new Endpoints, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#part-of-generate-file
14
-
15
- };
1
+ {{requireSomething}}
2
+ exports.init = () => {
3
+ // GET request
4
+ endpoint.get("/{{endpoint}}", Credentials, (req, res) => {
5
+ // @response
6
+ res.json({
7
+ code: 200,
8
+ status: "SUCCESS",
9
+ message: "GET request at /{{endpoint}}",
10
+ });
11
+ });
12
+
13
+ // Create new Endpoints, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#part-of-generate-file
14
+
15
+ };
@@ -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
+ };