create-sip 1.2.2 → 1.3.1
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/README.md +0 -195
- package/create-sip.js +1 -1
- package/expressapi/.env.example +10 -0
- package/expressapi/.env.test +7 -0
- package/expressapi/app/app.js +17 -0
- package/expressapi/app/controllers/authController.js +9 -11
- package/expressapi/app/database/database.js +14 -14
- package/expressapi/app/index.js +4 -18
- package/expressapi/app/middleware/authjwt.js +3 -4
- package/expressapi/docs/dev_doc.md +13 -1
- package/expressapi/docs/user_doc.md +93 -6
- package/expressapi/op +80 -52
- package/expressapi/package-lock.json +1285 -41
- package/expressapi/package.json +3 -1
- package/expressapi/test/{test.js → user.spec.js} +10 -10
- package/manager.js +18 -1
- package/package.json +1 -1
- package/expressapi/config/default.json.example +0 -15
package/expressapi/op
CHANGED
|
@@ -52,7 +52,7 @@ yargs(hideBin(process.argv))
|
|
|
52
52
|
}
|
|
53
53
|
)
|
|
54
54
|
.command('conf:generate',
|
|
55
|
-
'
|
|
55
|
+
'Generate a new config file: .env',
|
|
56
56
|
(yargs) => {
|
|
57
57
|
return yargs
|
|
58
58
|
},
|
|
@@ -60,6 +60,15 @@ yargs(hideBin(process.argv))
|
|
|
60
60
|
startGenerateConf();
|
|
61
61
|
}
|
|
62
62
|
)
|
|
63
|
+
.command('testconf:generate',
|
|
64
|
+
'Generate a new config file: .env.test',
|
|
65
|
+
(yargs) => {
|
|
66
|
+
return yargs
|
|
67
|
+
},
|
|
68
|
+
async (argv) => {
|
|
69
|
+
startGenerateTestConf();
|
|
70
|
+
}
|
|
71
|
+
)
|
|
63
72
|
.command('admin:generate',
|
|
64
73
|
'Generates a new admin user in database table: users',
|
|
65
74
|
(yargs) => {
|
|
@@ -241,45 +250,64 @@ function capitalizeFirstLetter(word) {
|
|
|
241
250
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
242
251
|
}
|
|
243
252
|
|
|
244
|
-
function startGenerateKey() {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
async function startGenerateKey() {
|
|
254
|
+
try {
|
|
255
|
+
const envFile = '.env'
|
|
256
|
+
let content = await fse.readFile(envFile, 'utf8')
|
|
257
|
+
const key = generateApiKey({method: 'bytes', length: 32})
|
|
258
|
+
|
|
259
|
+
const regex = /^APP_KEY *=.*$/m
|
|
260
|
+
if(regex.test(content)) {
|
|
261
|
+
content = content.replace(regex, `APP_KEY=${key}`)
|
|
262
|
+
}else {
|
|
263
|
+
if(content.trim() !== '') {
|
|
264
|
+
content += `\nAPP_KEY=${key}\n`
|
|
265
|
+
}else {
|
|
266
|
+
content = `APP_KEY=${key}\n`
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
fse.writeFile(envFile, content, 'utf8')
|
|
270
|
+
} catch (error) {
|
|
271
|
+
console.error(error)
|
|
272
|
+
}
|
|
256
273
|
}
|
|
257
274
|
|
|
258
275
|
async function startGenerateConf() {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
276
|
+
const content = `
|
|
277
|
+
APP_PORT=8000
|
|
278
|
+
APP_KEY=
|
|
279
|
+
APP_LOG=console.log
|
|
280
|
+
|
|
281
|
+
DB_DIALECT=sqlite
|
|
282
|
+
DB_HOST=127.0.0.1
|
|
283
|
+
DB_NAME=
|
|
284
|
+
DB_USER=
|
|
285
|
+
DB_PASS=
|
|
286
|
+
DB_PATH=:memory:
|
|
287
|
+
`
|
|
288
|
+
const destinationFileName = '.env'
|
|
262
289
|
if(await startCheckIfFileExists(destinationFileName)) {
|
|
263
290
|
process.exit(1);
|
|
264
291
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
} catch (error) {
|
|
268
|
-
console.log(error)
|
|
269
|
-
}
|
|
270
|
-
|
|
292
|
+
|
|
293
|
+
await fse.writeFile(destinationFileName, content, 'utf8')
|
|
271
294
|
}
|
|
272
295
|
|
|
273
|
-
async function
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
296
|
+
async function startGenerateTestConf() {
|
|
297
|
+
const content = `
|
|
298
|
+
APP_PORT=8000
|
|
299
|
+
APP_KEY=my_secret_key
|
|
300
|
+
APP_LOG=console.log
|
|
301
|
+
|
|
302
|
+
DB_DIALECT=sqlite
|
|
303
|
+
DB_PATH=:memory:
|
|
304
|
+
`
|
|
305
|
+
const destinationFileName = '.env.test'
|
|
306
|
+
if(await startCheckIfFileExists(destinationFileName)) {
|
|
307
|
+
process.exit(1);
|
|
282
308
|
}
|
|
309
|
+
|
|
310
|
+
await fse.writeFile(destinationFileName, content, 'utf8')
|
|
283
311
|
}
|
|
284
312
|
|
|
285
313
|
async function inputPassword() {
|
|
@@ -292,33 +320,33 @@ async function inputPassword() {
|
|
|
292
320
|
}
|
|
293
321
|
|
|
294
322
|
async function startGenerateAdmin() {
|
|
295
|
-
console.log('Generate admin...')
|
|
296
323
|
try {
|
|
297
|
-
const
|
|
298
|
-
|
|
324
|
+
const { default: User } = await import('./app/models/user.js')
|
|
325
|
+
await User.sync()
|
|
326
|
+
|
|
327
|
+
await import('dotenv').then((dotenv) => dotenv.config())
|
|
328
|
+
const isMemoryDb = process.env.DB_PATH === ':memory:';
|
|
299
329
|
if(isMemoryDb) {
|
|
300
330
|
console.log('Admin cannot be created in memory db!')
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
await User.sync()
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
304
333
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
const password = await inputPassword()
|
|
311
|
-
const hashedPassword = await bcrypt.hash(password, 10);
|
|
312
|
-
await User.create({
|
|
313
|
-
name: 'admin',
|
|
314
|
-
email: 'admin',
|
|
315
|
-
password: hashedPassword
|
|
316
|
-
})
|
|
317
|
-
console.log('Admin created!')
|
|
334
|
+
const isUserExist = await User.findOne({ where: { name: 'admin' } })
|
|
335
|
+
if (isUserExist) {
|
|
336
|
+
console.log('Admin already exists!')
|
|
337
|
+
return;
|
|
318
338
|
}
|
|
319
|
-
|
|
339
|
+
const password = await inputPassword()
|
|
340
|
+
const hashedPassword = await bcrypt.hash(password, 10);
|
|
341
|
+
await User.create({
|
|
342
|
+
name: 'admin',
|
|
343
|
+
email: 'admin',
|
|
344
|
+
password: hashedPassword
|
|
345
|
+
})
|
|
346
|
+
console.log('Admin created!')
|
|
347
|
+
} catch (error) {
|
|
320
348
|
console.error('Error creating admin!')
|
|
321
|
-
console.error(
|
|
349
|
+
console.error(error)
|
|
322
350
|
}
|
|
323
351
|
}
|
|
324
352
|
|