From 2832de1d991b2ab1185a626f5b5ad3ebbc6f83f1 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Fri, 27 Sep 2019 14:56:19 +0200 Subject: [PATCH] can create superuser --- packages/insights-api/src/app.ts | 5 ++++ .../src/services/users/users.class.ts | 1 + ...{createsuperuser.js => createsuperuser.ts} | 8 ++--- .../insights-cli/app/{index.js => index.ts} | 2 +- packages/insights-cli/bin/insights | 2 +- .../insights-cli/bin/insights-createsecret | 2 +- .../insights-cli/bin/insights-createsuperuser | 5 ++-- packages/insights-cli/bin/insights-start | 2 +- packages/insights-cli/package.json | 7 ++++- tsconfig.json | 2 +- yarn.lock | 29 +++++++++++++++++-- 11 files changed, 50 insertions(+), 15 deletions(-) rename packages/insights-cli/app/{createsuperuser.js => createsuperuser.ts} (89%) rename packages/insights-cli/app/{index.js => index.ts} (89%) diff --git a/packages/insights-api/src/app.ts b/packages/insights-api/src/app.ts index 3b3fe1f3..1bf5576c 100644 --- a/packages/insights-api/src/app.ts +++ b/packages/insights-api/src/app.ts @@ -23,6 +23,11 @@ const app: Application = express(feathers()); // Load app configuration app.configure(configuration()); + +if (process.env.INSIGHTS_DATA) { + app.set('nedb', process.env.INSIGHTS_DATA) +} + // Enable security, CORS, compression, favicon and body parsing app.use(helmet()); app.use(cors()); diff --git a/packages/insights-api/src/services/users/users.class.ts b/packages/insights-api/src/services/users/users.class.ts index c6d6c290..63620781 100644 --- a/packages/insights-api/src/services/users/users.class.ts +++ b/packages/insights-api/src/services/users/users.class.ts @@ -5,6 +5,7 @@ interface UserData { _id?: string; email: string; password: string; + roles: string[]; } export class Users extends Service { diff --git a/packages/insights-cli/app/createsuperuser.js b/packages/insights-cli/app/createsuperuser.ts similarity index 89% rename from packages/insights-cli/app/createsuperuser.js rename to packages/insights-cli/app/createsuperuser.ts index d2d87b81..5c5e86d8 100644 --- a/packages/insights-cli/app/createsuperuser.js +++ b/packages/insights-cli/app/createsuperuser.ts @@ -2,9 +2,9 @@ // - INSIGHTS_SUPERUSER_EMAIL // - INSIGHTS_SUPERUSER_PASSWORD -const app = require('insights-api/src') -const prompt = require('prompt-promise') -const randomString = require('../lib/random-string') +import app from '../../insights-api/src/app' +import prompt from 'prompt-promise' +import randomString from '../lib/random-string' const azAZ09 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' @@ -40,7 +40,7 @@ async function main () { } try { - await app.service('api/users').create({ + await app.service('users').create({ email: email, password: password, roles: ['superuser'] diff --git a/packages/insights-cli/app/index.js b/packages/insights-cli/app/index.ts similarity index 89% rename from packages/insights-cli/app/index.js rename to packages/insights-cli/app/index.ts index 6b2ce664..f77ff259 100644 --- a/packages/insights-cli/app/index.js +++ b/packages/insights-cli/app/index.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ const logger = require('winston') -const app = require('insights-core/src') +const app = require('insights-api/src') const port = process.env.INSIGHTS_PORT || app.get('port') diff --git a/packages/insights-cli/bin/insights b/packages/insights-cli/bin/insights index 2032b8be..3eed432d 100755 --- a/packages/insights-cli/bin/insights +++ b/packages/insights-cli/bin/insights @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env ts-node var path = require('path') var program = require('commander') diff --git a/packages/insights-cli/bin/insights-createsecret b/packages/insights-cli/bin/insights-createsecret index 9d35bf59..9f38d0b2 100755 --- a/packages/insights-cli/bin/insights-createsecret +++ b/packages/insights-cli/bin/insights-createsecret @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env ts-node var fs = require('fs') var path = require('path') diff --git a/packages/insights-cli/bin/insights-createsuperuser b/packages/insights-cli/bin/insights-createsuperuser index ba0b7218..5298c6f2 100755 --- a/packages/insights-cli/bin/insights-createsuperuser +++ b/packages/insights-cli/bin/insights-createsuperuser @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env ts-node var path = require('path') var program = require('commander') @@ -15,8 +15,7 @@ program.version(pkg.version) .option('-d --develop', 'Run in development mode') .parse(process.argv) -process.env.NODE_ENV = program.develop ? 'development' : 'production' -process.env.NODE_CONFIG_DIR = path.join(__dirname, '..', 'config') +process.env.NODE_CONFIG_DIR = path.join(__dirname, '..', '..', 'insights-api', 'config') process.env.INSIGHTS_DATA = program.data || path.join(require('os').homedir(), '.insights', 'data') if (program.email) { diff --git a/packages/insights-cli/bin/insights-start b/packages/insights-cli/bin/insights-start index 304b47da..c10eadc9 100755 --- a/packages/insights-cli/bin/insights-start +++ b/packages/insights-cli/bin/insights-start @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env ts-node // Thanks to https://github.com/mysamai/mysam/blob/master/bin/mysam for this script! diff --git a/packages/insights-cli/package.json b/packages/insights-cli/package.json index e8b2646c..7fafe688 100644 --- a/packages/insights-cli/package.json +++ b/packages/insights-cli/package.json @@ -35,6 +35,11 @@ ], "peerDependencies": {}, "dependencies": { - "commander": "^2.10.0" + "commander": "^2.10.0", + "prompt-promise": "^1.0.3" + }, + "devDependencies": { + "ts-node": "^8.4.1", + "typescript": "^3.6.3" } } diff --git a/tsconfig.json b/tsconfig.json index 98ffe6c0..e69e1564 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "module": "commonjs", "baseUrl": "./src", "outDir": "./lib", - "strict": true, + "strict": false, "esModuleInterop": true }, "exclude": [ diff --git a/yarn.lock b/yarn.lock index 7ec2e49b..dc37d70b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9534,6 +9534,11 @@ keymaster@^1.6.2: resolved "https://registry.yarnpkg.com/keymaster/-/keymaster-1.6.2.tgz#e1ae54d0ea9488f9f60b66b668f02e9a1946c6eb" integrity sha1-4a5U0OqUiPn2C2a2aPAumhlGxus= +keypress@~0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/keypress/-/keypress-0.2.1.tgz#1e80454250018dbad4c3fe94497d6e67b6269c77" + integrity sha1-HoBFQlABjbrUw/6USX1uZ7YmnHc= + killable@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892" @@ -10441,6 +10446,18 @@ nanomatch@^1.2.9: snapdragon "^0.8.1" to-regex "^3.0.1" +native-or-another@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/native-or-another/-/native-or-another-2.0.0.tgz#17a567f92beea9cd71acff96a7681a735eca3bff" + integrity sha1-F6Vn+Svuqc1xrP+Wp2gac17KO/8= + dependencies: + native-or-bluebird "^1.1.2" + +native-or-bluebird@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz#39c47bfd7825d1fb9ffad32210ae25daadf101c9" + integrity sha1-OcR7/Xgl0fuf+tMiEK4l2q3xAck= + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -12611,6 +12628,14 @@ promise@^7.1.1: dependencies: asap "~2.0.3" +prompt-promise@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/prompt-promise/-/prompt-promise-1.0.3.tgz#78ce4fcb9a14a108c49174f2d808c440d1bde265" + integrity sha1-eM5Py5oUoQjEkXTy2AjEQNG94mU= + dependencies: + keypress "~0.2.1" + native-or-another "~2.0.0" + prompts@^2.0.1: version "2.2.1" resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.2.1.tgz#f901dd2a2dfee080359c0e20059b24188d75ad35" @@ -15289,7 +15314,7 @@ ts-node-dev@^1.0.0-pre.43: ts-node "*" tsconfig "^7.0.0" -ts-node@*: +ts-node@*, ts-node@^8.4.1: version "8.4.1" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.4.1.tgz#270b0dba16e8723c9fa4f9b4775d3810fd994b4f" integrity sha512-5LpRN+mTiCs7lI5EtbXmF/HfMeCjzt7DH9CZwtkr6SywStrNQC723wG+aOWFiLNn7zT3kD/RnFqi3ZUfr4l5Qw== @@ -15429,7 +15454,7 @@ typescript-tuple@^2.2.1: dependencies: typescript-compare "^0.0.2" -typescript@3.6.3, typescript@^3.5.3: +typescript@3.6.3, typescript@^3.5.3, typescript@^3.6.3: version "3.6.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da" integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==