├── kb-cd-ui ├── src │ ├── assets │ │ └── .gitkeep │ ├── favicon.ico │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── app │ │ ├── ansi.pipe.spec.ts │ │ ├── app-routing.module.ts │ │ ├── ansi.pipe.ts │ │ ├── app.module.ts │ │ ├── app.component.spec.ts │ │ ├── app.component.html │ │ ├── app.component.scss │ │ └── app.component.ts │ ├── tsconfig.app.json │ ├── tslint.json │ ├── styles.scss │ ├── main.ts │ ├── tsconfig.spec.json │ ├── browserslist │ ├── index.html │ ├── test.ts │ ├── kb-mixin.scss │ └── polyfills.ts ├── e2e │ ├── tsconfig.e2e.json │ ├── src │ │ ├── app.po.ts │ │ └── app.e2e-spec.ts │ └── protractor.conf.js ├── tsconfig.json ├── .gitignore ├── jest.config.js ├── README.md ├── package.json ├── tslint.json └── angular.json ├── .gitignore ├── views ├── index.ejs ├── account.ejs ├── login.ejs └── error.ejs ├── src ├── index.ts ├── jest.config.js ├── interfaces.ts ├── cold-deck-route │ ├── cold-deck-route.ts │ ├── kb-unauthenticated-route.ts │ └── kb-authenticated-route.ts ├── cold-deck-module.nest.ts ├── firebase.transport.ts ├── expressLogger.ts ├── consts.ts ├── cold-deck.test.ts ├── lowdb.transport.ts ├── kb-access-setup.ts └── cold-deck.ts ├── .travis.yml ├── .all-contributorsrc ├── LICENSE ├── CONTRIBUTING.md ├── README.md ├── CODE_OF_CONDUCT.md ├── package.json ├── public ├── login.js └── login.css └── tsconfig.json /kb-cd-ui/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /kb-cd-ui/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kibibit/cold-deck/next/kb-cd-ui/src/favicon.ico -------------------------------------------------------------------------------- /kb-cd-ui/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | logs/ 3 | .env* 4 | firebase-* 5 | lib/ 6 | coverage/ 7 | test-report.html 8 | public/kb-cd-ui/ 9 | -------------------------------------------------------------------------------- /views/index.ejs: -------------------------------------------------------------------------------- 1 | <% if (!user) { %> 2 |

Welcome! Please log in.

3 | <% } else { %> 4 |

Hello, 5 | <%= user.displayName %>.

6 | <% } %> 7 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './consts'; 2 | export * from './cold-deck'; 3 | export * from './interfaces'; 4 | export * from './cold-deck-route/cold-deck-route'; 5 | export * from './cold-deck-module.nest'; 6 | -------------------------------------------------------------------------------- /src/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | coverageReporters: ["json", "lcov", "text", "clover", "html"], 5 | modulePathIgnorePatterns: ["/lib/"] 6 | }; 7 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/ansi.pipe.spec.ts: -------------------------------------------------------------------------------- 1 | import { AnsiPipe } from './ansi.pipe'; 2 | 3 | describe('AnsiPipe', () => { 4 | it('create an instance', () => { 5 | const pipe = new AnsiPipe(); 6 | expect(pipe).toBeTruthy(); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /kb-cd-ui/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /kb-cd-ui/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /views/account.ejs: -------------------------------------------------------------------------------- 1 |

ID: 2 | <%= user.id %> 3 |

4 |

Username: 5 | <%= user.username %> 6 |

7 |

Name: 8 | <%= user.displayName %> 9 |

10 |

Email: 11 | <%= user.emails[0].value %> 12 |

13 | 14 |

Organizations: 15 | <%= user.organizations.join(', ') %> 16 |

17 | -------------------------------------------------------------------------------- /kb-cd-ui/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/') as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | const routes: Routes = []; 5 | 6 | @NgModule({ 7 | imports: [RouterModule.forRoot(routes)], 8 | exports: [RouterModule] 9 | }) 10 | export class AppRoutingModule { } 11 | -------------------------------------------------------------------------------- /kb-cd-ui/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /kb-cd-ui/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | body { 4 | font-family: 'Comfortaa', cursive; 5 | } 6 | 7 | html { 8 | background-color: #212121; 9 | } 10 | 11 | app-root { 12 | display: flex; 13 | flex-direction: column; 14 | width: 100vw; 15 | height: 100vh; 16 | overflow: hidden; 17 | 18 | nav.navbar { 19 | height: 3.25rem; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /kb-cd-ui/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /kb-cd-ui/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "node", 7 | "jest" 8 | ], 9 | "module": "commonjs", 10 | "allowJs": true, 11 | "baseUrl": "./" 12 | }, 13 | "files": [ 14 | "test.ts", 15 | "polyfills.ts" 16 | ], 17 | "include": [ 18 | "**/*.spec.ts", 19 | "**/*.d.ts" 20 | ] 21 | } -------------------------------------------------------------------------------- /kb-cd-ui/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /kb-cd-ui/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | cache: npm 4 | node_js: 5 | - "8.3" 6 | notifications: 7 | email: false 8 | stages: 9 | # - compile 10 | - test 11 | - deploy 12 | jobs: 13 | include: 14 | - stage: test 15 | node_js: lts/* 16 | script: 17 | - npm run install:client 18 | - npm run coveralls 19 | - stage: release 20 | node_js: lts/* 21 | script: 22 | - npm run install:client 23 | - npm run build 24 | - npm run semantic-release 25 | branches: 26 | except: 27 | - /^v\d+\.\d+\.\d+$/ 28 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "cold-deck", 3 | "projectOwner": "kibibit", 4 | "repoType": "github", 5 | "repoHost": "https://github.com", 6 | "files": [ 7 | "README.md" 8 | ], 9 | "imageSize": 100, 10 | "commit": true, 11 | "contributors": [ 12 | { 13 | "login": "Thatkookooguy", 14 | "name": "Neil Kalman", 15 | "avatar_url": "https://avatars0.githubusercontent.com/u/10427304?s=460&v=4", 16 | "profile": "https://github.com/Thatkookooguy", 17 | "contributions": [ 18 | "infra", 19 | "design", 20 | "code" 21 | ] 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/ansi.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | import * as Convert from 'ansi-to-html'; 3 | import { DomSanitizer } from '@angular/platform-browser'; 4 | 5 | const convert = new Convert(); 6 | 7 | @Pipe({ 8 | name: 'ansi' 9 | }) 10 | export class AnsiPipe implements PipeTransform { 11 | 12 | constructor(private sanitized: DomSanitizer) { } 13 | 14 | transform(value: any, args?: any): any { 15 | console.log('got this!'); 16 | console.log(convert.toHtml(value)); 17 | return value ? this.sanitized.bypassSecurityTrustHtml(convert.toHtml(value)) : value; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/interfaces.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | import * as admin from "firebase-admin"; 3 | 4 | export interface KbLogger extends winston.Logger { 5 | table?: () => any; 6 | } 7 | 8 | export interface KbFirebaseOptions extends admin.AppOptions { 9 | projectId: string; 10 | collectionName?: string; 11 | } 12 | 13 | export interface KbColdDeckOptions { 14 | path: string; 15 | createDefaultConsole: boolean; 16 | firebase?: KbFirebaseOptions; 17 | } 18 | 19 | export interface KbLoggerOptions { 20 | transports?: any[]; 21 | persist?: boolean; 22 | scope?: string | { msg: string; colors: string; } 23 | } 24 | -------------------------------------------------------------------------------- /kb-cd-ui/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to kb-cd-ui!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | })); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /src/cold-deck-route/cold-deck-route.ts: -------------------------------------------------------------------------------- 1 | import { kbAuthenticatedRoute } from './kb-authenticated-route'; 2 | import { kbUnAuthenticatedRoute } from './kb-unauthenticated-route'; 3 | import { ColdDeck } from '../cold-deck'; 4 | 5 | export interface KbMiddlewareOptions { 6 | githubClient?: { 7 | githubClientId: string; 8 | githubClientSecret: string; 9 | redirectUrl: string; 10 | } 11 | } 12 | 13 | export function kbMiddleware(coldDeck: ColdDeck, options: KbMiddlewareOptions, allowedOrganization?: string, allowedUsers?: string[]) { 14 | if (options.githubClient) { 15 | return kbAuthenticatedRoute(coldDeck, options.githubClient, allowedOrganization, allowedUsers); 16 | } 17 | 18 | return kbUnAuthenticatedRoute(coldDeck); 19 | }; 20 | -------------------------------------------------------------------------------- /kb-cd-ui/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { HttpClientModule } from '@angular/common/http'; 2 | import { NgModule } from '@angular/core'; 3 | import { BrowserModule } from '@angular/platform-browser'; 4 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 5 | 6 | import { AnsiPipe } from './ansi.pipe'; 7 | import { AppRoutingModule } from './app-routing.module'; 8 | import { AppComponent } from './app.component'; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | AppComponent, 13 | AnsiPipe 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | BrowserAnimationsModule, 18 | HttpClientModule, 19 | AppRoutingModule 20 | ], 21 | providers: [], 22 | bootstrap: [ AppComponent ] 23 | }) 24 | export class AppModule { } 25 | -------------------------------------------------------------------------------- /kb-cd-ui/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # profiling files 12 | chrome-profiler-events.json 13 | speed-measure-plugin.json 14 | 15 | # IDEs and editors 16 | /.idea 17 | .project 18 | .classpath 19 | .c9/ 20 | *.launch 21 | .settings/ 22 | *.sublime-workspace 23 | 24 | # IDE - VSCode 25 | .vscode/* 26 | !.vscode/settings.json 27 | !.vscode/tasks.json 28 | !.vscode/launch.json 29 | !.vscode/extensions.json 30 | .history/* 31 | 32 | # misc 33 | /.sass-cache 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | npm-debug.log 38 | yarn-error.log 39 | testem.log 40 | /typings 41 | 42 | # System Files 43 | .DS_Store 44 | Thumbs.db 45 | -------------------------------------------------------------------------------- /src/cold-deck-module.nest.ts: -------------------------------------------------------------------------------- 1 | // beaver is the logger module for nest.js 2 | 3 | import { INestApplication } from '@nestjs/common'; 4 | import { KbColdDeckOptions, ColdDeck } from '.'; 5 | import { KbLogger } from './interfaces'; 6 | 7 | export class ColdDeckModule { 8 | static coldDeck: ColdDeck; 9 | static baseLogger: KbLogger; 10 | 11 | public static attachLogger( 12 | app: INestApplication, 13 | options: Partial = {} 14 | ): { logger: KbLogger; coldDeck: ColdDeck } { 15 | this.coldDeck = new ColdDeck(options); 16 | this.baseLogger = this.coldDeck.createBasic(); 17 | 18 | app.use('/logs', this.coldDeck.expressMiddleware({})); 19 | 20 | app.use(this.coldDeck.expressLogger()); 21 | 22 | return { 23 | logger: this.baseLogger, 24 | coldDeck: this.coldDeck 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /kb-cd-ui/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /kb-cd-ui/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @kibibit/cold-deck 7 | 8 | 9 | 11 | 14 | 16 | 18 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /kb-cd-ui/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "globals": { 3 | "ts-jest": { 4 | "tsConfigFile": "src/tsconfig.spec.json" 5 | }, 6 | "__TRANSFORM_HTML__": true 7 | }, 8 | "transform": { 9 | "^.+\\.(ts|js|html)$": "/node_modules/jest-preset-angular/preprocessor.js" 10 | }, 11 | "testMatch": [ 12 | "**/__tests__/**/*.+(ts|js)?(x)", 13 | "**/+(*.)+(spec|test).+(ts|js)?(x)" 14 | ], 15 | "moduleFileExtensions": [ 16 | "ts", 17 | "js", 18 | "html", 19 | "json" 20 | ], 21 | "transformIgnorePatterns": [ 22 | "node_modules/(?!@ngrx|ng2-truncate)" 23 | ], 24 | "snapshotSerializers": [ 25 | "/node_modules/jest-preset-angular/AngularSnapshotSerializer.js", 26 | "/node_modules/jest-preset-angular/HTMLCommentSerializer.js" 27 | ], 28 | "preset": "jest-preset-angular", 29 | "setupFilesAfterEnv": ["/src/test.ts"], 30 | "testURL": "http://localhost/" 31 | }; 32 | -------------------------------------------------------------------------------- /src/firebase.transport.ts: -------------------------------------------------------------------------------- 1 | import * as firebase from 'firebase-admin'; 2 | import { omit } from 'lodash'; 3 | const Transport = require('winston-transport'); 4 | 5 | export class KbFirebaseTransport extends Transport { 6 | name: string; 7 | level: string; 8 | ref: firebase.database.Reference; 9 | key: string; 10 | 11 | constructor(options) { 12 | super(options); 13 | 14 | this.name = options.name || 'FirebaseLogger'; 15 | this.level = options.level || 'silly'; 16 | this.ref = options.ref || 'logs'; 17 | this.key = options.key; 18 | } 19 | 20 | log(info, callback) { 21 | const key = info[ this.key ] || Date.now(); 22 | 23 | this.ref 24 | .update({ 25 | [ key ]: { 26 | level: info.level, 27 | message: info.message, 28 | meta: omit(info, [ 'level', 'message', this.key ]) 29 | } 30 | }) 31 | .then(() => { 32 | callback(null, true); 33 | 34 | this.emit('logged', info); 35 | }) 36 | .catch((error) => callback(error)); 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /kb-cd-ui/README.md: -------------------------------------------------------------------------------- 1 | # KbCdUi 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.2.3. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Neil Kalman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /kb-cd-ui/src/test.ts: -------------------------------------------------------------------------------- 1 | import 'jest-preset-angular'; 2 | 3 | // @ts-ignore 4 | global.CSS = null; 5 | 6 | const webStorageMock = () => { 7 | let storage: Record = {}; 8 | return { 9 | getItem: (key: string) => (key in storage ? storage[key] : null), 10 | setItem: (key: string, value: any) => (storage[key] = value || ''), 11 | removeItem: (key: string) => delete storage[key], 12 | clear: () => (storage = {}), 13 | }; 14 | }; 15 | 16 | Object.defineProperty(window, 'localStorage', { value: webStorageMock() }); 17 | Object.defineProperty(window, 'sessionStorage', { value: webStorageMock() }); 18 | Object.defineProperty(document, 'doctype', { 19 | value: '', 20 | }); 21 | Object.defineProperty(window, 'getComputedStyle', { 22 | value: () => { 23 | return { 24 | display: 'none', 25 | appearance: ['-webkit-appearance'], 26 | }; 27 | }, 28 | }); 29 | /** 30 | * ISSUE: https://github.com/angular/material2/issues/7101 31 | * Workaround for JSDOM missing transform property 32 | */ 33 | Object.defineProperty(document.body.style, 'transform', { 34 | value: () => { 35 | return { 36 | enumerable: true, 37 | configurable: true, 38 | }; 39 | }, 40 | }); 41 | -------------------------------------------------------------------------------- /kb-cd-ui/src/kb-mixin.scss: -------------------------------------------------------------------------------- 1 | @mixin scrolling-shadows($background-color: transparent, $shadow-intensity: 0.2, $shadow-color: black, $cover-size: 40px, $shadow-size: 14px) { 2 | // Shadow covers 3 | background: linear-gradient($background-color 30%, rgba($background-color, 0)), linear-gradient(rgba($background-color, 0), $background-color 70%) 0 100%, 4 | radial-gradient(50% 0, farthest-side, rgba($shadow-color, $shadow-intensity), rgba($shadow-color, 0)), radial-gradient(50% 100%, farthest-side, rgba($shadow-color, $shadow-intensity), rgba($shadow-color, 0)) 0 100%; 5 | background: linear-gradient($background-color 30%, rgba($background-color, 0)), linear-gradient(rgba($background-color, 0), $background-color 70%) 0 100%, 6 | radial-gradient(farthest-side at 50% 0, rgba($shadow-color, $shadow-intensity), rgba($shadow-color, 0)); 7 | // also add button shadow: 8 | //radial-gradient(farthest-side at 50% 100%, rgba($shadow-color,$shadow-intensity), rgba($shadow-color,0)) 0 100%; 9 | background-repeat: no-repeat; 10 | background-color: $background-color; 11 | background-size: 100% $cover-size, 100% $cover-size, 100% $shadow-size, 100% $shadow-size; 12 | // Opera doesn't support this in the shorthand 13 | background-attachment: local, local, scroll, scroll; 14 | } 15 | -------------------------------------------------------------------------------- /src/expressLogger.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import * as winston from 'winston'; 3 | import { get } from 'lodash'; 4 | 5 | import { ColdDeck } from './cold-deck'; 6 | import { KbLoggerOptions } from './interfaces'; 7 | import { KbLowDbTransport } from './lowdb.transport'; 8 | 9 | export function createExpressLogger(coldDeck: ColdDeck, options: KbLoggerOptions = {}) { 10 | const kbConsole = coldDeck.child({ 11 | persist: options.persist, 12 | scope: options.scope || 'Express', 13 | transports: [ 14 | new KbLowDbTransport({ folder: path.join(coldDeck.globalOptions.path) }) 15 | ] 16 | }); 17 | 18 | return function (req, res, next) { 19 | const logParams = { 20 | scope: { msg: 'express', colors: 'bgYellow.magenta' }, 21 | tags: [ 22 | { msg: req.ip.includes('127.0.0.1') || req.ip.startsWith('::1') ? 'localhost' : req.ip, colors: 'red' }, 23 | { msg: req.method, colors: 'green' }, 24 | { 25 | msg: (/mobile/i.test(req.headers[ 'user-agent' ]) ? 'MOBILE' : 'DESKTOP'), 26 | colors: 'grey' 27 | } 28 | ] 29 | }; 30 | 31 | if (get(req, 'user.username')) { 32 | logParams.tags.push({ msg: get(req, 'user.username'), colors: 'bgBlue.yellow' }); 33 | } 34 | 35 | kbConsole.info(req.url, logParams); 36 | 37 | next(); 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | import { AnsiPipe } from './ansi.pipe'; 5 | import { HttpClientModule } from '@angular/common/http'; 6 | 7 | describe('AppComponent', () => { 8 | beforeEach(async(() => { 9 | TestBed.configureTestingModule({ 10 | imports: [ 11 | HttpClientModule, 12 | RouterTestingModule 13 | ], 14 | declarations: [ 15 | AppComponent, 16 | AnsiPipe, 17 | ], 18 | }).compileComponents(); 19 | })); 20 | 21 | it('should create the app', () => { 22 | const fixture = TestBed.createComponent(AppComponent); 23 | const app = fixture.debugElement.componentInstance; 24 | expect(app).toBeTruthy(); 25 | }); 26 | 27 | it(`should have as title 'kb-cd-ui'`, () => { 28 | const fixture = TestBed.createComponent(AppComponent); 29 | const app = fixture.debugElement.componentInstance; 30 | expect(app.title).toEqual('kb-cd-ui'); 31 | }); 32 | 33 | it('should render title in the navbar', () => { 34 | const fixture = TestBed.createComponent(AppComponent); 35 | fixture.detectChanges(); 36 | const compiled = fixture.debugElement.nativeElement; 37 | expect(compiled.querySelector('nav .kb-title').textContent).toContain('cold-deck'); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /kb-cd-ui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kb-cd-ui", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "start:dev": "ng serve --proxy-config proxy.config.json", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "test:watch": "jest --watch" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/animations": "~7.2.0", 17 | "@angular/common": "~7.2.0", 18 | "@angular/compiler": "~7.2.0", 19 | "@angular/core": "~7.2.0", 20 | "@angular/forms": "~7.2.0", 21 | "@angular/platform-browser": "~7.2.0", 22 | "@angular/platform-browser-dynamic": "~7.2.0", 23 | "@angular/router": "~7.2.0", 24 | "@davinkevin/jest": "^0.1.0", 25 | "ansi-to-html": "^0.6.10", 26 | "bulmaswatch": "^0.7.2", 27 | "core-js": "^2.5.4", 28 | "rxjs": "~6.3.3", 29 | "tslib": "^1.9.0", 30 | "zone.js": "~0.8.26" 31 | }, 32 | "devDependencies": { 33 | "@angular-devkit/build-angular": "~0.12.0", 34 | "@angular/cli": "~7.2.3", 35 | "@angular/compiler-cli": "~7.2.0", 36 | "@angular/language-service": "~7.2.0", 37 | "@types/jasmine": "~2.8.8", 38 | "@types/jasminewd2": "~2.0.3", 39 | "@types/jest": "^22.2.0", 40 | "@types/karma": "^3.0.2", 41 | "@types/karma-jasmine": "0.0.31", 42 | "@types/node": "~8.9.4", 43 | "codelyzer": "~4.5.0", 44 | "jasmine-core": "~2.99.1", 45 | "jasmine-spec-reporter": "~4.2.1", 46 | "jest": "^22.4.2", 47 | "jest-preset-angular": "^5.2.1", 48 | "karma": "~3.1.1", 49 | "karma-chrome-launcher": "~2.2.0", 50 | "karma-coverage-istanbul-reporter": "~2.0.1", 51 | "karma-jasmine": "~1.1.2", 52 | "karma-jasmine-html-reporter": "^0.2.2", 53 | "protractor": "~5.4.0", 54 | "ts-node": "~7.0.0", 55 | "tslint": "~5.11.0", 56 | "typescript": "~3.2.2" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 20 |
21 |
22 |
24 |
{{ hour }}
25 |
26 |
27 |
28 |
30 | 31 |
34 | 35 | {{ log.icon }} 36 | 37 |
38 |
{{ log.scope.msg ? log.scope.msg : log.scope }}
40 |
41 | 44 | {{ tag.msg ? tag.msg : tag }} 45 | 46 |
47 |
50 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /src/consts.ts: -------------------------------------------------------------------------------- 1 | import colors from 'colors'; 2 | import moment from 'moment'; 3 | import * as winston from 'winston'; 4 | import { isString, isObject, get, map, uniqueId } from 'lodash'; 5 | import { KbColdDeckOptions } from './interfaces'; 6 | 7 | // keeps consts and default values 8 | 9 | export const firebaseAppMapper = {}; 10 | 11 | export const kbDefaultLogLevels = { 12 | levels: { 13 | error: 0, 14 | warn: 1, 15 | info: 2, 16 | verbose: 3, 17 | debug: 4, 18 | silly: 5 19 | }, 20 | colors: { 21 | verbose: colors.bgGreen, 22 | silly: colors.bgBlue, 23 | info: colors.blue, 24 | debug: colors.green, 25 | warn: colors.yellow, 26 | error: colors.red 27 | } 28 | }; 29 | 30 | export const coldDeckDefaultOptions: KbColdDeckOptions = { 31 | path: 'logs', 32 | createDefaultConsole: true 33 | }; 34 | 35 | const consolePrettyPrint = winston.format.printf(({ level, message, scope, timestamp, tags }) => { 36 | const parsedTimestamp = moment(timestamp).format('YYYY-MM-DD [||] HH:mm:ss'); 37 | const parsedTags = map(tags, (tag) => get(colors, tag.colors)(`[${ tag.msg }]`)); 38 | 39 | let parsedLabel = parseScope(scope); 40 | parsedLabel = parsedLabel ? ` ${ parsedLabel }` : ''; 41 | 42 | return `${ colors.green(parsedTimestamp) } ${ kbDefaultLogLevels.colors[ level ](level.toUpperCase()) }${ parsedLabel }${ parsedTags.length ? ' - ' + parsedTags.join('') : '' }: ${ message }`; 43 | 44 | function parseScope(scope: string | { msg: string; colors: string }) { 45 | if (isString(scope)) { 46 | return colors.bgWhite.magenta(`${ scope.toUpperCase() }`); 47 | } 48 | 49 | if (isObject(scope)) { 50 | const scopeColors = get(colors, scope.colors) || colors.bgWhite.magenta; 51 | 52 | return scopeColors(`${ scope.msg.toUpperCase() }`); 53 | } 54 | 55 | return ''; 56 | } 57 | }); 58 | 59 | const addKeyToInfo = winston.format((info) => { 60 | info.key = uniqueId(info.timestamp.replace(/\..*$/, '') + `::${ info.scope.msg ? info.scope.msg : info.scope }::`); 61 | 62 | return info; 63 | }); 64 | 65 | export const kbFormatters = { 66 | consolePrettyPrint, 67 | addKeyToInfo 68 | }; 69 | -------------------------------------------------------------------------------- /src/cold-deck.test.ts: -------------------------------------------------------------------------------- 1 | import { ColdDeck } from './cold-deck'; 2 | 3 | it('should create an instance successfully', () => { 4 | const instance = new ColdDeck(); 5 | 6 | return expect(instance).toBeTruthy(); 7 | }); 8 | 9 | it('should create a basic logger and log a message', () => { 10 | const instance = new ColdDeck(); 11 | 12 | const logger = instance.createBasic(); 13 | 14 | return expect(logger).toBeTruthy(); 15 | }); 16 | 17 | it('should successfully create child logger', () => { 18 | const instance = new ColdDeck(); 19 | 20 | const logger = instance.child({}); 21 | 22 | return expect(logger).toBeTruthy(); 23 | }); 24 | 25 | // console.log('got the host?', process.env.DB_HOST); 26 | 27 | // const serviceAccount = require(process.env.FIREBASE_CREDENTIAL_FILE || ''); 28 | 29 | // if (!process.env.PROJECT_ID) { throw new Error('project id must be defined'); } 30 | 31 | // const firebaseSettings = { 32 | // // FIREBASE 33 | // apiKey: process.env.API_KEY, 34 | // authDomain: process.env.AUTH_DOMAIN, 35 | // databaseURL: process.env.DATABASE_URL, 36 | // projectId: process.env.PROJECT_ID, 37 | // storageBucket: process.env.STORAGE_BUCKET, 38 | // messagingSenderId: process.env.MESSAGING_SENDER_ID, 39 | // credential: admin.credential.cert(serviceAccount) 40 | // }; 41 | 42 | // const basicLogger = new ColdDeck({ 43 | // path: './logs', 44 | // firebase: firebaseSettings 45 | // }); 46 | 47 | // const nana = basicLogger.createBasic({ persist: true }); 48 | 49 | // nana.info('this is from the test file!'); 50 | 51 | // const childLogger = basicLogger.child({ persist: true }); 52 | 53 | // childLogger.info('this is a child!', { service: 'tits', ass: 'is nice' }); 54 | 55 | 56 | // /* jshint -W098 */ 57 | // (function () { 58 | // const express = require('express'), 59 | // app = express(); 60 | 61 | // app.set('port', 11109); 62 | 63 | // app.use(basicLogger.expressLogger({ persist: true })); //Log each request 64 | 65 | // var port = app.get("port"); 66 | 67 | // app.get('/', function (req, res) { 68 | // res.send('hello world'); 69 | // }); 70 | 71 | // app.listen(port, function () { 72 | // nana.info('Server listening at port ' + port); 73 | // }); 74 | // })(); 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | [fork]: /fork 4 | [pr]: /compare 5 | [style]: https://standardjs.com/ 6 | [code-of-conduct]: CODE_OF_CONDUCT.md 7 | 8 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 9 | 10 | Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms. 11 | 12 | ## Issues and PRs 13 | 14 | If you have suggestions for how this project could be improved, or want to report a bug, open an issue! We'd love all and any contributions. If you have questions, too, we'd love to hear them. 15 | 16 | We'd also love PRs. If you're thinking of a large PR, we advise opening up an issue first to talk about it, though! Look at the links below if you're not sure how to open a PR. 17 | 18 | ## Submitting a pull request 19 | 20 | 1. [Fork][fork] and clone the repository. 21 | 1. Configure and install the dependencies: `npm install`. 22 | 1. Make sure the tests pass on your machine: `npm test`, note: these tests also apply the linter, so there's no need to lint separately. 23 | 1. Create a new branch: `git checkout -b my-branch-name`. 24 | 1. Make your change, add tests, and make sure the tests still pass. 25 | 1. Push to your fork and [submit a pull request][pr]. 26 | 1. Pat your self on the back and wait for your pull request to be reviewed and merged. 27 | 28 | Here are a few things you can do that will increase the likelihood of your pull request being accepted: 29 | 30 | - Follow the [style guide][style] which is using standard. Any linting errors should be shown when running `npm test`. 31 | - Write and update tests. 32 | - Keep your changes as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. 33 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 34 | 35 | Work in Progress pull requests are also welcome to get feedback early on, or if there is something blocked you. 36 | 37 | ## Resources 38 | 39 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 40 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 41 | - [GitHub Help](https://help.github.com) 42 | -------------------------------------------------------------------------------- /src/cold-deck-route/kb-unauthenticated-route.ts: -------------------------------------------------------------------------------- 1 | import bodyParser from 'body-parser'; 2 | import express from 'express'; 3 | import partials from 'express-partials'; 4 | import methodOverride from 'method-override'; 5 | import { ColdDeck } from '../cold-deck'; 6 | import path from 'path'; 7 | import FileAsync from 'lowdb/adapters/FileAsync'; 8 | import moment from 'moment'; 9 | import fs from 'fs-extra'; 10 | import lowdb from 'lowdb'; 11 | 12 | export function kbUnAuthenticatedRoute(coldDeck: ColdDeck): express.Express { 13 | 14 | const webPanel = express(); 15 | 16 | webPanel.set('views', __dirname + '/../../views'); 17 | webPanel.set('view engine', 'ejs'); 18 | webPanel.set('view engine', 'html'); 19 | webPanel.use(partials()); 20 | webPanel.use(bodyParser.urlencoded({ extended: true })); 21 | webPanel.use(bodyParser.json()); 22 | webPanel.use(methodOverride()); 23 | webPanel.use(express.static(__dirname + '/../../public')); 24 | webPanel.use(errorHandler); 25 | 26 | webPanel.get('/', function (req, res) { 27 | res.sendFile(path.join(__dirname + '/../../public/kb-cd-ui/index.html')); 28 | }); 29 | 30 | webPanel.get('/logs', function (req, res, next) { 31 | const day = moment.utc().format('YYYY-MM-DD'); 32 | const adapter = new FileAsync(process.cwd() + `/logs/${ day }.json`); 33 | 34 | fs.ensureFile(process.cwd() + `/logs/${ day }.json`) 35 | .then(() => lowdb(adapter)) 36 | .then((db) => { 37 | // send this day's database 38 | const todaysLogs = db.getState(); 39 | 40 | res.json(todaysLogs); 41 | 42 | // we later need to also open a web-socket channel to update for changes in today's logs' wdb 43 | }) 44 | .catch((err) => next(err)); 45 | }); 46 | 47 | webPanel.get('/log-days', function (req, res, next) { 48 | const directoryPath = path.join(process.cwd(), '/logs'); 49 | 50 | fs.readdir(directoryPath) 51 | .then((files) => res.json(files)) 52 | .catch((err) => next(err)); 53 | }); 54 | 55 | webPanel.get('*', function (req, res) { 56 | res.status(404); 57 | res.render('error.ejs', { error: `the page you are looking for can't be found`, statusCode: 404 }); 58 | }); 59 | 60 | return webPanel; 61 | 62 | function errorHandler(err, req, res, next) { 63 | res.status(500); 64 | res.render('error.ejs', { error: err }); 65 | } 66 | 67 | }; 68 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | @import '../kb-mixin.scss'; 2 | 3 | .kb-title { 4 | font-family: 'Lobster Two', cursive; 5 | font-size: 2rem; 6 | margin-left: 0.2em; 7 | } 8 | 9 | .hour-graph { 10 | display: flex; 11 | height: 80px; 12 | width: 100%; 13 | position: relative; 14 | background: rgba(0, 0, 0, 0.3); 15 | 16 | .single-hour { 17 | padding: 0 2px; 18 | flex: auto; 19 | border-left: 1px solid rgba(148, 148, 148, 0.07); 20 | justify-content: center; 21 | position: relative; 22 | 23 | &:first-child { 24 | border-left: none; 25 | } 26 | 27 | .hour-label { 28 | position: absolute; 29 | left: 3px; 30 | right: 3px; 31 | top: 5px; 32 | font-size: 0.6em; 33 | text-align: center; 34 | letter-spacing: 1px; 35 | line-height: 10px; 36 | pointer-events: none; 37 | -webkit-font-smoothing: auto; 38 | } 39 | } 40 | } 41 | 42 | .kb-logs { 43 | font-family: Hack, monospace; 44 | font-size: 0.8em; 45 | overflow-y: auto; 46 | height: calc(100% - 80px); 47 | // @include scrolling-shadows; 48 | } 49 | 50 | .kb-log { 51 | display: flex; 52 | align-items: stretch; 53 | padding: 0 1em; 54 | 55 | >* { 56 | margin: 0 0.2em; 57 | } 58 | 59 | .kb-scope, 60 | .kb-level { 61 | text-transform: uppercase; 62 | font-weight: bold; 63 | padding: 0.1em; 64 | display: flex; 65 | align-items: center; 66 | justify-content: center; 67 | margin-top: 0.3em; 68 | margin-bottom: 0.3em; 69 | } 70 | 71 | .kb-row-num { 72 | width: 35px; 73 | } 74 | 75 | .kb-scope { 76 | width: 83px; 77 | } 78 | } 79 | 80 | .search { 81 | flex-grow: 1; 82 | 83 | input { 84 | display: none; 85 | } 86 | } 87 | 88 | .logged-in-user { 89 | display: flex; 90 | align-items: center; 91 | padding: 0 0.5em; 92 | 93 | img { 94 | height: 3em; 95 | border-radius: 50%; 96 | margin-right: 0.3em; 97 | } 98 | } 99 | 100 | .kb-tags { 101 | width: 300px; 102 | background: black; 103 | 104 | .kb-tag { 105 | display: inline-block; 106 | padding: 0.2em; 107 | margin: 0 0.2em; 108 | border-radius: 0.1em; 109 | // background: rebeccapurple; 110 | } 111 | } 112 | 113 | .main-section { 114 | height: calc(100% - 3.25rem); 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | @kibibit/cold-deck 5 |

6 |

7 |

8 | 9 |

10 |

11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |

20 |

21 | A pile of stored logs, often around the base of a spar-tree 22 |

23 |
24 | 25 | (**WIP** - this is still a work in progress) 26 | 27 | Heavly inspired by [**Scribe.js**]() 28 | 29 | Node.js logging made simple! 30 | 31 | - works on top of [winston]() 32 | - saves logs to /logs folder 33 | - built in express logger 34 | - built in table logger 35 | - ability to save logs to firebase DB 36 | 37 | ## Contributing 38 | 39 | If you have suggestions for how tdd1t could be improved, or want to report a bug, open an issue! We'd love all and any contributions. 40 | 41 | For more, check out the [Contributing Guide](CONTRIBUTING.md). 42 | 43 | ## Contributors 44 | 45 | 46 | 47 |
Neil Kalman
Neil Kalman

🚇 🎨 💻
48 | 49 | 50 | 51 | ## License 52 | 53 | [MIT](LICENSE) © 2019 Neil Kalman 54 | -------------------------------------------------------------------------------- /src/lowdb.transport.ts: -------------------------------------------------------------------------------- 1 | import { mapValues, clone } from 'lodash'; 2 | import lowdb from 'lowdb'; 3 | import FileAsync from 'lowdb/adapters/FileAsync'; 4 | import moment from 'moment'; 5 | import fs from 'fs-extra'; 6 | 7 | import { kbDefaultLogLevels } from './consts'; 8 | 9 | const Transport = require('winston-transport'); 10 | export class KbLowDbTransport extends Transport { 11 | name: string; 12 | level: string; 13 | ref: lowdb.LowdbAsync; 14 | key: string; 15 | initPromise: Promise = Promise.resolve(); 16 | folder: string; 17 | 18 | constructor(options) { 19 | super(options); 20 | 21 | this.name = options.name || 'lowdbLogger'; 22 | this.level = options.level || 'silly'; 23 | this.ref = options.ref; 24 | this.key = options.key; 25 | this.folder = options.folder || './'; 26 | } 27 | 28 | log(info: any, callback: (...args: any[]) => {}) { 29 | const key = info[ this.key ] || Date.now(); 30 | const hour = moment.utc().format('HH:00'); 31 | 32 | this.db() 33 | .then(() => this.ref.get('logs').push({ key, ...info }).write()) 34 | .then(() => this.ref.update(`${ hour }.${ info.level }`, n => n + 1).write()) 35 | .then(() => { 36 | callback(null, true); 37 | 38 | this.emit('logged', info); 39 | }) 40 | .catch((error) => callback(error)); 41 | } 42 | 43 | private async db() { 44 | const day = moment.utc().format('YYYY-MM-DD'); 45 | const adapter = new FileAsync(this.folder + `/${ day }.json`); 46 | 47 | return fs.ensureFile(this.folder + `/${ day }.json`) 48 | .then(() => lowdb(adapter)) 49 | .then((db) => { 50 | this.ref = db; 51 | 52 | const levelCounters = mapValues(kbDefaultLogLevels.levels, () => 0); 53 | 54 | const hoursOfDay = mapValues({ 55 | '00:00': 0, 56 | '01:00': 0, 57 | '02:00': 0, 58 | '03:00': 0, 59 | '04:00': 0, 60 | '05:00': 0, 61 | '06:00': 0, 62 | '07:00': 0, 63 | '08:00': 0, 64 | '09:00': 0, 65 | '10:00': 0, 66 | '11:00': 0, 67 | '12:00': 0, 68 | '13:00': 0, 69 | '14:00': 0, 70 | '15:00': 0, 71 | '16:00': 0, 72 | '17:00': 0, 73 | '18:00': 0, 74 | '19:00': 0, 75 | '20:00': 0, 76 | '21:00': 0, 77 | '22:00': 0, 78 | '23:00': 0 79 | }, () => clone(levelCounters)); 80 | 81 | return this.ref.defaults({ logs: [], ...hoursOfDay }).write(); 82 | }) 83 | .then(() => this.ref); 84 | } 85 | }; 86 | -------------------------------------------------------------------------------- /src/kb-access-setup.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { Answers, InputStreamOption, Question, Questions, prompt } from 'inquirer'; 4 | import { isFunction } from 'lodash'; 5 | import pify from 'pify'; 6 | import { } from 'travis-ci'; 7 | 8 | // This setup should handle (and ask for): 9 | // - People with access to logs 10 | // - Organization or team (array of github users)? 11 | // - if Organization, which team inside the organization? 12 | // - Create a GitHub oAuth application under the user OR organization for logs 13 | // - make sure .dotenv files are `.gitignor`-ed 14 | // - Set everything in a `.dotenv` file for logs to access locally (should ask user first) 15 | // - Set everything up in travis (like semantic release does) 16 | 17 | const defineUsersOrOrganization: Question = { 18 | message: 'Should these logs be accessed by a GitHub Organization or a should define individual GitHub Users?', 19 | name: 'processType', 20 | type: 'list', 21 | choices: [ 'GitHub Organization', 'Define Team Now' ] 22 | }; 23 | 24 | const organizationQuestion: Question = { 25 | message: 'Enter a name of a github organization', 26 | name: 'organizationName', 27 | type: 'input' 28 | }; 29 | 30 | const teamQuestion: Question = { 31 | message: 'Enter GitHub usernames separated by spaces', 32 | name: 'teamMemberUsernames', 33 | type: 'input' 34 | }; 35 | 36 | export const askForProcessType: Question[] = [ 37 | defineUsersOrOrganization 38 | ]; 39 | 40 | export const askForOrganization: Question[] = [ 41 | organizationQuestion, 42 | ]; 43 | 44 | export const askForTeam: Question[] = [ 45 | teamQuestion, 46 | ]; 47 | 48 | export function defineLogsAccessTeam(): Promise { 49 | let isOrganization: boolean; 50 | return prompt(askForProcessType) 51 | .then((answers: Answers) => isOrganization = answers.processType === 'GitHub Organization') 52 | .then(() => prompt(isOrganization ? askForOrganization : askForTeam)); 53 | } 54 | 55 | class CliTool { 56 | private promptFn: (() => Promise) | undefined; 57 | private questions: Question[] = []; 58 | constructor(option: (() => Promise) | Question[]) { 59 | console.log('Constructing CliTool Instance'); 60 | 61 | if (isFunction(option)) { 62 | this.promptFn = option; 63 | } else { 64 | this.questions = option; 65 | } 66 | 67 | 68 | } 69 | 70 | public run() { 71 | console.log('CliTool Instance Started'); 72 | const questionAsked = this.promptFn ? this.promptFn() : prompt(this.questions); 73 | 74 | questionAsked.then((answers: Answers) => { 75 | console.log(answers); 76 | }); 77 | 78 | } 79 | } 80 | 81 | const cliTool = new CliTool(defineLogsAccessTeam); 82 | 83 | cliTool.run(); 84 | -------------------------------------------------------------------------------- /views/login.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cold-Deck Authentication 6 | 7 | 9 | 10 | 12 | 14 | 16 | 18 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
30 | 31 |
32 |
33 |
34 |

kibibit

35 |

36 | 38 | cold-deck 39 |

40 |
41 |
42 |

Log-in

43 |

Please Login with your GitHub account

44 |
45 | 52 |
53 | <% if (message && message.length > 0) { %> 54 | <%- message %> 55 | <% } %> 56 |
57 | Having trouble? 59 |
60 | 61 | 62 | 63 | 64 | 66 | 67 | 68 | 71 | 75 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /kb-cd-ui/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Component, OnInit } from '@angular/core'; 3 | import { DomSanitizer } from '@angular/platform-browser'; 4 | import { forEach, isString, lowerCase } from 'lodash'; 5 | 6 | interface KbUser { 7 | displayName: string; 8 | emails: string[]; 9 | organizations: string[]; 10 | username: string; 11 | avatar: string; 12 | } 13 | 14 | interface KbLog { 15 | message: string; 16 | level: string | { msg: string; colors: string }; 17 | scope: string | { msg: string; colors: string }; 18 | timestamp: string; 19 | tags?: string | { msg: string; colors: string }; 20 | icon?: string; 21 | } 22 | 23 | interface KbLogs { 24 | logs: KbLog[]; 25 | } 26 | 27 | @Component({ 28 | selector: 'app-root', 29 | templateUrl: './app.component.html', 30 | styleUrls: [ './app.component.scss' ] 31 | }) 32 | export class AppComponent implements OnInit { 33 | title = 'kb-cd-ui'; 34 | loggedInUser: KbUser; 35 | logs: KbLog[]; 36 | 37 | constructor(private http: HttpClient, private sanitized: DomSanitizer) { } 38 | 39 | ngOnInit(): void { 40 | this.http.get('./user') 41 | .subscribe((user) => { 42 | this.loggedInUser = user; 43 | 44 | console.log(this.loggedInUser); 45 | }); 46 | 47 | this.http.get('./logs') 48 | .subscribe((logs) => { 49 | console.log('all logs!'); 50 | console.log(logs); 51 | 52 | this.logs = logs.logs; 53 | 54 | forEach(this.logs, (log) => { 55 | const levelName = isString(log.level) ? log.level.toLowerCase() : log.level.msg.toLowerCase(); 56 | if (levelName === 'info') { 57 | return log.icon = 'info'; 58 | } 59 | 60 | if (levelName === 'warn') { 61 | return log.icon = 'warning'; 62 | } 63 | 64 | if (levelName === 'error') { 65 | return log.icon = 'block'; 66 | } 67 | 68 | log.icon = ''; 69 | }); 70 | }); 71 | } 72 | 73 | getTagStyle(tag: string | { msg: string; colors: string }) { 74 | if (isString(tag)) { return ''; } 75 | 76 | let style = ''; 77 | 78 | style += tag.colors.indexOf('bgYellow') > -1 ? 'background: hsl(48, 100%, 67%);' : ''; 79 | style += tag.colors.indexOf('magenta') > -1 ? 'color: hsl(348, 100%, 61%);' : ''; 80 | style += tag.colors.indexOf('red') > -1 ? 'color: hsl(348, 100%, 61%);' : ''; 81 | style += tag.colors.indexOf('grey') > -1 ? 'color: hsl(0, 0%, 71%);' : ''; 82 | style += tag.colors.indexOf('green') > -1 ? 'color: hsl(141, 71%, 48%);' : ''; 83 | 84 | return this.sanitized.bypassSecurityTrustStyle(style); 85 | } 86 | 87 | getColor(logLevel?: string) { 88 | logLevel = lowerCase(logLevel); 89 | 90 | if (logLevel === 'info') { 91 | return 'hsl(204, 86%, 53%)'; 92 | } 93 | 94 | if (logLevel === 'warn') { 95 | return 'hsl(48, 100%, 67%)'; 96 | } 97 | 98 | if (logLevel === 'error') { 99 | return 'hsl(348, 100%, 61%)'; 100 | } 101 | 102 | return 'transparent'; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | education, socio-economic status, nationality, personal appearance, race, 10 | religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at Neilkalman@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | -------------------------------------------------------------------------------- /kb-cd-ui/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /kb-cd-ui/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10, IE11, and Chrome <55 requires all of the following polyfills. 22 | * This also includes Android Emulators with older versions of Chrome and Google Search/Googlebot 23 | */ 24 | 25 | // import 'core-js/es6/symbol'; 26 | // import 'core-js/es6/object'; 27 | // import 'core-js/es6/function'; 28 | // import 'core-js/es6/parse-int'; 29 | // import 'core-js/es6/parse-float'; 30 | // import 'core-js/es6/number'; 31 | // import 'core-js/es6/math'; 32 | // import 'core-js/es6/string'; 33 | // import 'core-js/es6/date'; 34 | // import 'core-js/es6/array'; 35 | // import 'core-js/es6/regexp'; 36 | // import 'core-js/es6/map'; 37 | // import 'core-js/es6/weak-map'; 38 | // import 'core-js/es6/set'; 39 | 40 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 41 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 42 | 43 | /** IE10 and IE11 requires the following for the Reflect API. */ 44 | // import 'core-js/es6/reflect'; 45 | 46 | /** 47 | * Web Animations `@angular/platform-browser/animations` 48 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 49 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 50 | */ 51 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 52 | 53 | /** 54 | * By default, zone.js will patch all possible macroTask and DomEvents 55 | * user can disable parts of macroTask/DomEvents patch by setting following flags 56 | * because those flags need to be set before `zone.js` being loaded, and webpack 57 | * will put import in the top of bundle, so user need to create a separate file 58 | * in this directory (for example: zone-flags.ts), and put the following flags 59 | * into that file, and then add the following code before importing zone.js. 60 | * import './zone-flags.ts'; 61 | * 62 | * The flags allowed in zone-flags.ts are listed here. 63 | * 64 | * The following flags will work for all browsers. 65 | * 66 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 67 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 68 | * (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 69 | * 70 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 71 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 72 | * 73 | * (window as any).__Zone_enable_cross_context_check = true; 74 | * 75 | */ 76 | 77 | /*************************************************************************************************** 78 | * Zone JS is required by default for Angular itself. 79 | */ 80 | import 'zone.js/dist/zone'; // Included with Angular CLI. 81 | 82 | 83 | /*************************************************************************************************** 84 | * APPLICATION IMPORTS 85 | */ 86 | -------------------------------------------------------------------------------- /kb-cd-ui/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "kb-cd-ui": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": { 12 | "@schematics/angular:component": { 13 | "style": "scss" 14 | } 15 | }, 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "deployUrl": "./kb-cd-ui/", 21 | "outputPath": "../public/kb-cd-ui", 22 | "index": "src/index.html", 23 | "main": "src/main.ts", 24 | "polyfills": "src/polyfills.ts", 25 | "tsConfig": "src/tsconfig.app.json", 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets" 29 | ], 30 | "styles": [ 31 | "src/styles.scss" 32 | ], 33 | "scripts": [] 34 | }, 35 | "configurations": { 36 | "production": { 37 | "fileReplacements": [{ 38 | "replace": "src/environments/environment.ts", 39 | "with": "src/environments/environment.prod.ts" 40 | }], 41 | "optimization": true, 42 | "outputHashing": "all", 43 | "sourceMap": false, 44 | "extractCss": true, 45 | "namedChunks": false, 46 | "aot": true, 47 | "extractLicenses": true, 48 | "vendorChunk": false, 49 | "buildOptimizer": true, 50 | "budgets": [{ 51 | "type": "initial", 52 | "maximumWarning": "2mb", 53 | "maximumError": "5mb" 54 | }] 55 | } 56 | } 57 | }, 58 | "serve": { 59 | "builder": "@angular-devkit/build-angular:dev-server", 60 | "options": { 61 | "browserTarget": "kb-cd-ui:build" 62 | }, 63 | "configurations": { 64 | "production": { 65 | "browserTarget": "kb-cd-ui:build:production" 66 | } 67 | } 68 | }, 69 | "extract-i18n": { 70 | "builder": "@angular-devkit/build-angular:extract-i18n", 71 | "options": { 72 | "browserTarget": "kb-cd-ui:build" 73 | } 74 | }, 75 | "test": { 76 | "builder": "@davinkevin/jest:test", 77 | "options": { 78 | "main": "src/test.ts", 79 | "polyfills": "src/polyfills.ts", 80 | "tsConfig": "src/tsconfig.spec.json", 81 | "karmaConfig": "src/karma.conf.js", 82 | "styles": [ 83 | "src/styles.scss" 84 | ], 85 | "scripts": [], 86 | "assets": [ 87 | "src/favicon.ico", 88 | "src/assets" 89 | ] 90 | } 91 | }, 92 | "lint": { 93 | "builder": "@angular-devkit/build-angular:tslint", 94 | "options": { 95 | "tsConfig": [ 96 | "src/tsconfig.app.json", 97 | "src/tsconfig.spec.json" 98 | ], 99 | "exclude": [ 100 | "**/node_modules/**" 101 | ] 102 | } 103 | } 104 | } 105 | }, 106 | "kb-cd-ui-e2e": { 107 | "root": "e2e/", 108 | "projectType": "application", 109 | "prefix": "", 110 | "architect": { 111 | "e2e": { 112 | "builder": "@angular-devkit/build-angular:protractor", 113 | "options": { 114 | "protractorConfig": "e2e/protractor.conf.js", 115 | "devServerTarget": "kb-cd-ui:serve" 116 | }, 117 | "configurations": { 118 | "production": { 119 | "devServerTarget": "kb-cd-ui:serve:production" 120 | } 121 | } 122 | }, 123 | "lint": { 124 | "builder": "@angular-devkit/build-angular:tslint", 125 | "options": { 126 | "tsConfig": "e2e/tsconfig.e2e.json", 127 | "exclude": [ 128 | "**/node_modules/**" 129 | ] 130 | } 131 | } 132 | } 133 | } 134 | }, 135 | "defaultProject": "kb-cd-ui" 136 | } 137 | -------------------------------------------------------------------------------- /src/cold-deck.ts: -------------------------------------------------------------------------------- 1 | import * as admin from 'firebase-admin'; 2 | import { get, isNil } from 'lodash'; 3 | import path from 'path'; 4 | import * as winston from 'winston'; 5 | 6 | import { coldDeckDefaultOptions, firebaseAppMapper, kbDefaultLogLevels, kbFormatters } from './consts'; 7 | import { createExpressLogger } from './expressLogger'; 8 | import { KbFirebaseTransport } from './firebase.transport'; 9 | import { KbColdDeckOptions, KbLogger, KbLoggerOptions } from './interfaces'; 10 | import { KbLowDbTransport } from './lowdb.transport'; 11 | import { kbMiddleware, KbMiddlewareOptions } from './cold-deck-route/cold-deck-route'; 12 | 13 | export class ColdDeck { 14 | /* All the loggers created with cold deck. holds all child loggers */ 15 | static consoles = []; 16 | /* A Pointer to the main logger created with cold deck. */ 17 | static mainConsole: ColdDeck; 18 | /* holds the global options inherited by all child loggers */ 19 | globalOptions: KbColdDeckOptions; 20 | /* if logs should be backed up to a firebase DB, this will hold the firebase app instance */ 21 | firebaseApp: admin.app.App | undefined; 22 | 23 | constructor(options?: Partial) { 24 | options = isNil(options) ? {} : options; 25 | 26 | options = Object.assign({}, coldDeckDefaultOptions, options); 27 | 28 | this.globalOptions = options as KbColdDeckOptions; 29 | 30 | const existingDBId = get(this.globalOptions, 'firebase.projectId'); 31 | if (options.firebase && existingDBId && !firebaseAppMapper[ existingDBId ]) { 32 | firebaseAppMapper[ existingDBId ] = admin.initializeApp(options.firebase, options.firebase.projectId); 33 | this.firebaseApp = firebaseAppMapper[ existingDBId ]; 34 | } 35 | } 36 | 37 | /** 38 | * Get the express logger to attach as an express middleware 39 | */ 40 | expressLogger(options?: KbLoggerOptions) { 41 | return createExpressLogger(this, options); 42 | } 43 | 44 | expressMiddleware(options: KbMiddlewareOptions, allowedOrganization?: string, allowedUsers?: string[]) { 45 | return kbMiddleware(this, options, allowedOrganization, allowedUsers); 46 | } 47 | 48 | /** 49 | * Create a new child logger based on this instance of ColdDeck 50 | */ 51 | child(options: KbLoggerOptions) { 52 | return this.createBasic(options); 53 | } 54 | 55 | /** 56 | * Create a basic logger that will act as the main logger 57 | */ 58 | createBasic(options?: KbLoggerOptions): KbLogger { 59 | options = options || {}; 60 | 61 | const format = winston.format.combine( 62 | // winston.format.colorize(), 63 | winston.format.timestamp(), 64 | kbFormatters.addKeyToInfo(), 65 | winston.format.json() 66 | ); 67 | 68 | const newLogger: winston.Logger = winston.createLogger({ 69 | level: 'info', 70 | levels: kbDefaultLogLevels.levels, 71 | format, 72 | defaultMeta: { scope: options.scope || 'global' }, 73 | transports: options.transports || [ 74 | // 75 | // - Write all log levels to a daily basis JSON database file under given path 76 | // 77 | new KbLowDbTransport({ folder: path.join(this.globalOptions.path) }) 78 | ] 79 | }); 80 | 81 | // add firebase logger 82 | if (options.persist && this.firebaseApp) { 83 | console.log('adding firebase transporter!'); 84 | this.initializeFirebase(newLogger); 85 | } 86 | 87 | // winston.addColors(myCustomLevels.colors); 88 | 89 | if (process.env.NODE_ENV !== 'production') { 90 | const consoleTransport = new winston.transports.Console({ 91 | format: kbFormatters.consolePrettyPrint 92 | }); 93 | 94 | newLogger.add(consoleTransport); 95 | } 96 | 97 | // this.mainConsole = this.mainConsole || newLogger; 98 | 99 | // add a table option: 100 | (newLogger as KbLogger).table = () => { }; 101 | const kbLogger: KbLogger = newLogger as KbLogger; 102 | 103 | 104 | 105 | return kbLogger; 106 | } 107 | 108 | private initializeFirebase(logger: winston.Logger) { 109 | if (!this.firebaseApp || !this.globalOptions.firebase) { return; } 110 | 111 | const db = this.firebaseApp.database(); 112 | 113 | let collectionName = this.globalOptions.firebase.collectionName || 'application-logs'; 114 | collectionName = collectionName.endsWith('-logs') ? collectionName : `${ collectionName }-logs`; 115 | 116 | // @ts-ignore 117 | logger.add(new KbFirebaseTransport({ 118 | ref: db.ref(collectionName), 119 | key: 'key' 120 | })); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@kibibit/cold-deck", 3 | "version": "1.5.0-next.2", 4 | "description": "logs module", 5 | "types": "lib/index.d.ts", 6 | "main": "lib/index.js", 7 | "files": [ 8 | "/lib", 9 | "/views", 10 | "/public" 11 | ], 12 | "bin": { 13 | "cold-deck": "lib/kb-access-setup.js" 14 | }, 15 | "scripts": { 16 | "build": "tsc && npm run build:client", 17 | "test:watch": "jest --watchAll", 18 | "test": "jest --coverage", 19 | "coveralls": "npm run test && cat ./coverage/lcov.info | coveralls", 20 | "semantic-release": "semantic-release", 21 | "contributors:add": "all-contributors add", 22 | "contributors:generate": "all-contributors generate", 23 | "update:dep": "npm-check", 24 | "app-install": "npm install && npm run install:client", 25 | "install:client": "cd kb-cd-ui && npm install", 26 | "build:client": "cd kb-cd-ui && ng build --prod --aot", 27 | "announce": "announce-it" 28 | }, 29 | "author": "neilkalman@gmail.com", 30 | "license": "MIT", 31 | "announcements": { 32 | "tweet": "It's time to neatly pile all your logs.\nCold-Deck: a pile of logs stored away from the immediate area where logging is taking place.\n<%= package %> <%= version %> in out!\n\n<%= npmpage %>" 33 | }, 34 | "release": { 35 | "branches": [ 36 | "master", 37 | { 38 | "name": "next", 39 | "prerelease": true 40 | } 41 | ], 42 | "npmPublish": true, 43 | "analyzeCommits": [ 44 | "@semantic-release/commit-analyzer" 45 | ], 46 | "verifyConditions": [ 47 | "@semantic-release/npm", 48 | "@semantic-release/git", 49 | "@semantic-release/github" 50 | ], 51 | "prepare": [ 52 | "@semantic-release/npm", 53 | { 54 | "path": "@semantic-release/git", 55 | "assets": [ 56 | "package.json" 57 | ], 58 | "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" 59 | } 60 | ], 61 | "publish": [ 62 | "@semantic-release/npm", 63 | "@semantic-release/github" 64 | ], 65 | "success": [ 66 | "@semantic-release/github", 67 | [ 68 | "@semantic-release/exec", 69 | { 70 | "successCmd": "npm run announce -- --branch $TRAVIS_BRANCH" 71 | } 72 | ] 73 | ], 74 | "fail": [ 75 | "@semantic-release/github" 76 | ] 77 | }, 78 | "devDependencies": { 79 | "@kibibit/announce-it": "^2.0.0", 80 | "@semantic-release/commit-analyzer": "^6.1.0", 81 | "@semantic-release/exec": "^3.4.0-beta.2", 82 | "@semantic-release/git": "^7.1.0-beta.3", 83 | "@semantic-release/github": "^5.2.10", 84 | "@semantic-release/npm": "^5.1.4", 85 | "@semantic-release/release-notes-generator": "^7.1.4", 86 | "@types/callsite": "^1.0.30", 87 | "@types/connect-flash": "0.0.34", 88 | "@types/ejs": "^2.6.3", 89 | "@types/express": "^4.16.1", 90 | "@types/express-partials": "0.0.31", 91 | "@types/express-session": "^1.15.12", 92 | "@types/fs-extra": "^5.0.5", 93 | "@types/inquirer": "0.0.44", 94 | "@types/jest": "^24.0.11", 95 | "@types/lodash": "^4.14.123", 96 | "@types/lowdb": "^1.0.7", 97 | "@types/marked": "^0.6.3", 98 | "@types/method-override": "0.0.31", 99 | "@types/passport": "^1.0.0", 100 | "@types/passport-github2": "^1.2.4", 101 | "@types/pify": "^3.0.2", 102 | "all-contributors-cli": "^6.1.2", 103 | "coveralls": "^3.0.3", 104 | "firebase-mock": "^2.2.10", 105 | "jest": "^24.5.0", 106 | "jest-html-reporter": "^2.5.0", 107 | "ncp": "^2.0.0", 108 | "npm-check": "^5.9.0", 109 | "semantic-release": "^16.0.0-beta.22", 110 | "semantic-release-cli": "^4.1.0", 111 | "ts-jest": "^24.0.0", 112 | "ts-node": "^8.0.3", 113 | "typescript": "^3.3.3333" 114 | }, 115 | "repository": { 116 | "type": "git", 117 | "url": "https://github.com/Kibibit/cold-deck.git" 118 | }, 119 | "dependencies": { 120 | "@nestjs/common": "^6.1.1", 121 | "@octokit/rest": "^16.19.0", 122 | "body-parser": "^1.18.3", 123 | "callsite": "^1.0.0", 124 | "colors": "^1.3.3", 125 | "connect-flash": "^0.1.1", 126 | "ejs": "^2.6.1", 127 | "express": "^4.16.4", 128 | "express-partials": "^0.3.0", 129 | "express-session": "^1.15.6", 130 | "firebase-admin": "^7.0.0", 131 | "fs-extra": "^7.0.1", 132 | "inquirer": "^6.2.2", 133 | "lodash": "^4.17.11", 134 | "lowdb": "^1.0.0", 135 | "marked": "^0.6.1", 136 | "method-override": "^3.0.0", 137 | "mkdirp": "^0.5.1", 138 | "moment": "^2.24.0", 139 | "passport": "^0.4.0", 140 | "passport-github2": "^0.1.11", 141 | "pify": "^4.0.1", 142 | "travis-ci": "^2.2.0", 143 | "winston": "^3.2.1" 144 | }, 145 | "jest": { 146 | "projects": [ 147 | "kb-cd-ui/jest.config.js", 148 | "src/jest.config.js" 149 | ] 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /public/login.js: -------------------------------------------------------------------------------- 1 | particlesJS("particles-js", { 2 | "particles": { 3 | "number": { 4 | "value": 80, 5 | "density": { 6 | "enable": true, 7 | "value_area": 800 8 | } 9 | }, 10 | "color": { 11 | "value": "#EEB146" 12 | }, 13 | "shape": { 14 | "type": "circle", 15 | "stroke": { 16 | "width": 0, 17 | "color": "#000000" 18 | }, 19 | "polygon": { 20 | "nb_sides": 5 21 | }, 22 | "image": { 23 | "src": "img/github.svg", 24 | "width": 100, 25 | "height": 100 26 | } 27 | }, 28 | "opacity": { 29 | "value": 1, 30 | "random": false, 31 | "anim": { 32 | "enable": false, 33 | "speed": 1, 34 | "opacity_min": 0.1, 35 | "sync": false 36 | } 37 | }, 38 | "size": { 39 | "value": 144.3001443001443, 40 | "random": true, 41 | "anim": { 42 | "enable": true, 43 | "speed": 40, 44 | "size_min": 0.1, 45 | "sync": false 46 | } 47 | }, 48 | "line_linked": { 49 | "enable": false, 50 | "distance": 150, 51 | "color": "#ffffff", 52 | "opacity": 0.4, 53 | "width": 1 54 | }, 55 | "move": { 56 | "enable": true, 57 | "speed": 1, 58 | "direction": "none", 59 | "random": true, 60 | "straight": false, 61 | "out_mode": "bounce", 62 | "bounce": false, 63 | "attract": { 64 | "enable": true, 65 | "rotateX": 1282.667949334616, 66 | "rotateY": 1603.3349366682698 67 | } 68 | } 69 | }, 70 | "interactivity": { 71 | "detect_on": "canvas", 72 | "events": { 73 | "onhover": { 74 | "enable": true, 75 | "mode": "repulse" 76 | }, 77 | "onclick": { 78 | "enable": true, 79 | "mode": "push" 80 | }, 81 | "resize": true 82 | }, 83 | "modes": { 84 | "grab": { 85 | "distance": 400, 86 | "line_linked": { 87 | "opacity": 1 88 | } 89 | }, 90 | "bubble": { 91 | "distance": 400, 92 | "size": 40, 93 | "duration": 2, 94 | "opacity": 8, 95 | "speed": 3 96 | }, 97 | "repulse": { 98 | "distance": 200, 99 | "duration": 0.4 100 | }, 101 | "push": { 102 | "particles_nb": 4 103 | }, 104 | "remove": { 105 | "particles_nb": 2 106 | } 107 | } 108 | }, 109 | "retina_detect": true 110 | }); 111 | 112 | particlesJS("particles-js2", { 113 | "particles": { 114 | "number": { 115 | "value": 80, 116 | "density": { 117 | "enable": true, 118 | "value_area": 800 119 | } 120 | }, 121 | "color": { 122 | "value": "#00A2C9" 123 | }, 124 | "shape": { 125 | "type": "circle", 126 | "stroke": { 127 | "width": 0, 128 | "color": "#000000" 129 | }, 130 | "polygon": { 131 | "nb_sides": 5 132 | }, 133 | "image": { 134 | "src": "img/github.svg", 135 | "width": 100, 136 | "height": 100 137 | } 138 | }, 139 | "opacity": { 140 | "value": 1, 141 | "random": false, 142 | "anim": { 143 | "enable": false, 144 | "speed": 1, 145 | "opacity_min": 0.1, 146 | "sync": false 147 | } 148 | }, 149 | "size": { 150 | "value": 100, 151 | "random": true, 152 | "anim": { 153 | "enable": true, 154 | "speed": 40, 155 | "size_min": 10, 156 | "sync": false 157 | } 158 | }, 159 | "line_linked": { 160 | "enable": false, 161 | "distance": 150, 162 | "color": "#ffffff", 163 | "opacity": 0.4, 164 | "width": 1 165 | }, 166 | "move": { 167 | "enable": true, 168 | "speed": 1, 169 | "direction": "none", 170 | "random": true, 171 | "straight": false, 172 | "out_mode": "bounce", 173 | "bounce": false, 174 | "attract": { 175 | "enable": true, 176 | "rotateX": 1282.667949334616, 177 | "rotateY": 1603.3349366682698 178 | } 179 | } 180 | }, 181 | "interactivity": { 182 | "detect_on": "canvas", 183 | "events": { 184 | "onhover": { 185 | "enable": true, 186 | "mode": "repulse" 187 | }, 188 | "onclick": { 189 | "enable": true, 190 | "mode": "push" 191 | }, 192 | "resize": true 193 | }, 194 | "modes": { 195 | "grab": { 196 | "distance": 400, 197 | "line_linked": { 198 | "opacity": 1 199 | } 200 | }, 201 | "bubble": { 202 | "distance": 400, 203 | "size": 40, 204 | "duration": 2, 205 | "opacity": 8, 206 | "speed": 3 207 | }, 208 | "repulse": { 209 | "distance": 200, 210 | "duration": 0.4 211 | }, 212 | "push": { 213 | "particles_nb": 4 214 | }, 215 | "remove": { 216 | "particles_nb": 2 217 | } 218 | } 219 | }, 220 | "retina_detect": true 221 | }); 222 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "es5", 5 | /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 6 | "module": "commonjs", 7 | /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 8 | "lib": ["es2016"], 9 | /* Specify library files to be included in the compilation. */ 10 | // "allowJs": true, /* Allow javascript files to be compiled. */ 11 | // "checkJs": true, /* Report errors in .js files. */ 12 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 13 | "declaration": true, 14 | /* Generates corresponding '.d.ts' file. */ 15 | "declarationMap": true, 16 | /* Generates a sourcemap for each corresponding '.d.ts' file. */ 17 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 18 | // "outFile": "./", /* Concatenate and emit output to single file. */ 19 | "outDir": "./lib", 20 | /* Redirect output structure to the directory. */ 21 | "rootDir": "./src", 22 | /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 23 | // "composite": true, /* Enable project compilation */ 24 | // "removeComments": true, /* Do not emit comments to output. */ 25 | // "noEmit": true, /* Do not emit outputs. */ 26 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 27 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 28 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 29 | 30 | /* Strict Type-Checking Options */ 31 | "strict": true, 32 | /* Enable all strict type-checking options. */ 33 | "noImplicitAny": false, 34 | /* Raise error on expressions and declarations with an implied 'any' type. */ 35 | // "strictNullChecks": true, /* Enable strict null checks. */ 36 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 37 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 38 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 39 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 40 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 41 | 42 | /* Additional Checks */ 43 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 44 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 45 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 46 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 47 | 48 | /* Module Resolution Options */ 49 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 50 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 51 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 52 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 53 | "typeRoots": ["./types", "./node_modules/@types"], 54 | /* List of folders to include type definitions from. */ 55 | // "types": [], /* Type declaration files to be included in compilation. */ 56 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 57 | "esModuleInterop": true, 58 | /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 59 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 60 | 61 | /* Source Map Options */ 62 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 63 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 64 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 65 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 66 | 67 | /* Experimental Options */ 68 | "experimentalDecorators": true, 69 | /* Enables experimental support for ES7 decorators. */ 70 | "emitDecoratorMetadata": true, 71 | /* Enables experimental support for emitting type metadata for decorators. */ 72 | }, 73 | "include": [ 74 | "src/**/*" 75 | ] 76 | } 77 | -------------------------------------------------------------------------------- /views/error.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | kibibit - 7 | <%= statusCode %> 8 | 9 | 10 | 13 | 14 | 16 | 17 | 19 | 20 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 |
77 |
78 |
79 |
oops. sorry about that...
80 |
----
81 |
82 | <%- error %> 83 |
84 |
85 | 86 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /public/login.css: -------------------------------------------------------------------------------- 1 | .kb-message { 2 | min-height: 75px; 3 | } 4 | 5 | .kb-info-overlay { 6 | position: absolute; 7 | bottom: 0; 8 | left: 0; 9 | background: white; 10 | padding: 10px; 11 | min-width: 20px; 12 | height: 35px; 13 | z-index: 4; 14 | } 15 | 16 | html { 17 | box-sizing: border-box; 18 | } 19 | 20 | *, 21 | *:before, 22 | *:after { 23 | box-sizing: inherit; 24 | } 25 | 26 | html, 27 | body { 28 | padding: 0px; 29 | margin: 0px; 30 | overflow: hidden; 31 | } 32 | 33 | #particles-js, 34 | #particles-js2 { 35 | top: 0; 36 | left: 0; 37 | position: absolute; 38 | width: 100%; 39 | height: 100%; 40 | background-color: #f25757; 41 | background-image: url(""); 42 | background-repeat: no-repeat; 43 | background-size: cover; 44 | background-position: 50% 50%; 45 | } 46 | 47 | #particles-js canvas, 48 | #particles-js2 canvas { 49 | filter: url(#goo); 50 | display: block; 51 | vertical-align: bottom; 52 | } 53 | 54 | #particles-js2 { 55 | background-color: transparent; 56 | } 57 | 58 | .bg-overlay { 59 | position: absolute; 60 | top: 0; 61 | left: 0; 62 | } 63 | 64 | .red { 65 | color: #f25757; 66 | } 67 | 68 | .blue { 69 | color: #00A2C9; 70 | } 71 | 72 | .yellow { 73 | color: #EEB146; 74 | } 75 | 76 | h1.kibibit-logo { 77 | font-family: 'Righteous', cursive; 78 | letter-spacing: 0.1em; 79 | font-size: 1rem; 80 | margin-bottom: 0 !important; 81 | } 82 | 83 | h1.achievibit { 84 | margin-top: 0 !important; 85 | } 86 | 87 | .bg-overlay { 88 | width: 100vw; 89 | height: 100vh; 90 | background-color: rgba(0, 0, 0, 0.4); 91 | z-index: 2; 92 | } 93 | 94 | body { 95 | margin: 0; 96 | background-color: #F25757; 97 | width: 100vw; 98 | height: 100vh; 99 | display: flex; 100 | justify-content: center; 101 | align-items: center; 102 | font-family: 'Comfortaa', cursive; 103 | font-size: 14px; 104 | } 105 | 106 | body .button:focus:not(:active) { 107 | border-color: #ffdd57; 108 | color: #ffdd57; 109 | box-shadow: 0 0 0 0.125em rgba(255, 221, 87, 0); 110 | box-shadow: 0; 111 | } 112 | 113 | body .kb-having-trouble { 114 | position: relative; 115 | } 116 | 117 | body .kb-having-trouble:after { 118 | position: absolute; 119 | top: 0; 120 | bottom: 0; 121 | left: -0.7em; 122 | right: -0.7em; 123 | content: ""; 124 | border: 1px solid #ffdd57; 125 | border-radius: 3px; 126 | opacity: 0; 127 | transition: opacity 250ms; 128 | } 129 | 130 | body .kb-having-trouble:focus { 131 | outline: none; 132 | } 133 | 134 | body .kb-having-trouble:focus:after { 135 | opacity: 1; 136 | } 137 | 138 | .kb-card .symbol { 139 | position: absolute; 140 | top: 0; 141 | width: 4rem; 142 | height: 4rem; 143 | transform: translate3d(0, -100%, 0); 144 | } 145 | 146 | .kb-card .symbol svg { 147 | width: 4rem; 148 | height: 4rem; 149 | } 150 | 151 | .kb-card .symbol svg .axe { 152 | fill: #EEB146; 153 | } 154 | 155 | .kb-card .symbol svg .fist { 156 | fill: white; 157 | } 158 | 159 | .kb-card { 160 | top: 0; 161 | left: 0; 162 | right: 0; 163 | bottom: 0; 164 | margin: auto; 165 | position: absolute; 166 | max-width: 360px; 167 | max-height: 460px; 168 | background-color: #212121; 169 | border-radius: 5px; 170 | padding: 40px; 171 | overflow-x: hidden; 172 | box-shadow: 0 3px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2); 173 | z-index: 3; 174 | transition: all 300ms; 175 | overflow-y: hidden; 176 | overflow: visible; 177 | } 178 | 179 | .kb-card.transition { 180 | border-radius: 100%; 181 | max-width: 80px; 182 | max-height: 80px; 183 | overflow: hidden; 184 | background: #EEB146; 185 | } 186 | 187 | .kb-card.transition .loader { 188 | opacity: 1; 189 | } 190 | 191 | .kb-card .content { 192 | height: 100%; 193 | display: flex; 194 | flex-direction: column; 195 | justify-content: space-between; 196 | transition: all 200ms; 197 | } 198 | 199 | .kb-card #troubles { 200 | color: #4285f4; 201 | display: inline-block; 202 | padding: 10px; 203 | padding-left: 0; 204 | border-radius: 5px; 205 | cursor: pointer; 206 | } 207 | 208 | .kb-card .splash { 209 | background-image: linear-gradient(to bottom, rgba(233, 233, 233, 0) 0%, rgba(233, 233, 233, 0) 62.22%, #e9e9e9 40.22%, rgba(233, 233, 233, 0) 100%); 210 | position: relative; 211 | left: -42px; 212 | width: 404px; 213 | } 214 | 215 | .kb-card .splash svg { 216 | transform: scale(-1, 1); 217 | width: 50%; 218 | max-width: 90vw; 219 | } 220 | 221 | .kb-card .splash #yubikey-identifier { 222 | animation-duration: 1s; 223 | animation-name: insert; 224 | animation-iteration-count: infinite; 225 | animation-direction: alternate; 226 | animation-timing-function: ease-in-out; 227 | } 228 | 229 | @keyframes insert { 230 | 0% { 231 | transform: translateX(-10px); 232 | } 233 | 234 | 20% { 235 | transform: translateX(-10px); 236 | } 237 | 238 | 80% { 239 | transform: translateX(0); 240 | } 241 | 242 | 100% { 243 | transform: translateX(0); 244 | } 245 | } 246 | 247 | .loader { 248 | opacity: 0; 249 | width: 80px; 250 | height: 80px; 251 | position: absolute; 252 | left: 0; 253 | top: 0; 254 | right: 0; 255 | bottom: 0; 256 | margin: auto; 257 | border: 0 solid transparent; 258 | border-radius: 50%; 259 | transition: all 450ms; 260 | background: #EEB146; 261 | } 262 | 263 | .loader:before, 264 | .loader:after { 265 | content: ''; 266 | border-radius: 50%; 267 | width: inherit; 268 | height: inherit; 269 | position: absolute; 270 | top: 0; 271 | left: 0; 272 | animation: loader-07 1s linear infinite; 273 | opacity: 0; 274 | background: #f25757; 275 | } 276 | 277 | .loader:before { 278 | animation-delay: 1s; 279 | background: #00A2C9; 280 | } 281 | 282 | .loader:after { 283 | animation-delay: .5s; 284 | } 285 | 286 | @keyframes loader-07 { 287 | 0% { 288 | transform: scale(0); 289 | opacity: 0; 290 | } 291 | 292 | 50% { 293 | opacity: 1; 294 | } 295 | 296 | 100% { 297 | transform: scale(1); 298 | opacity: 0; 299 | } 300 | } 301 | 302 | .kb-login-buttons .button { 303 | justify-content: flex-start; 304 | transition: all 250ms; 305 | padding-left: 50px; 306 | } 307 | 308 | .kb-login-buttons .button:hover { 309 | background: rgba(0, 0, 0, 0.3); 310 | } 311 | 312 | .kb-login-buttons .button i { 313 | margin: 0 0.5em; 314 | } 315 | -------------------------------------------------------------------------------- /src/cold-deck-route/kb-authenticated-route.ts: -------------------------------------------------------------------------------- 1 | import bodyParser from 'body-parser'; 2 | import express, { Router } from 'express'; 3 | import partials from 'express-partials'; 4 | import session from 'express-session'; 5 | import methodOverride from 'method-override'; 6 | import passport from 'passport'; 7 | import { Strategy as GitHubStrategy } from 'passport-github2'; 8 | import flash from 'connect-flash'; 9 | import { isEmpty, isArray, compact } from 'lodash'; 10 | import marked from 'marked'; 11 | import Octokit from '@octokit/rest'; 12 | import path from 'path'; 13 | import fs from 'fs-extra'; 14 | import lowdb from 'lowdb'; 15 | import FileAsync from 'lowdb/adapters/FileAsync'; 16 | import moment from 'moment'; 17 | import { ColdDeck } from '../cold-deck'; 18 | 19 | interface KbUser { 20 | displayName: string; 21 | emails: string[]; 22 | organizations: string[]; 23 | username: string; 24 | avatar: string; 25 | } 26 | 27 | interface KbGithubClient { 28 | githubClientId: string; 29 | githubClientSecret: string; 30 | redirectUrl: string; 31 | } 32 | 33 | export function kbAuthenticatedRoute(coldDeck: ColdDeck, githubClient: KbGithubClient, allowedOrganization?: string, allowedUsers?: string[]): express.Express { 34 | // Passport session setup. 35 | // To support persistent login sessions, Passport needs to be able to 36 | // serialize users into and deserialize users out of the session. Typically, 37 | // this will be as simple as storing the user ID when serializing, and finding 38 | // the user by ID when deserializing. However, since this example does not 39 | // have a database of user records, the complete GitHub profile is serialized 40 | // and deserialized. 41 | passport.serializeUser(function (user, done) { 42 | done(null, user); 43 | }); 44 | 45 | passport.deserializeUser(function (obj, done) { 46 | done(null, obj); 47 | }); 48 | 49 | // Use the GitHubStrategy within Passport. 50 | // Strategies in Passport require a `verify` function, which accept 51 | // credentials (in this case, an accessToken, refreshToken, and GitHub 52 | // profile), and invoke a callback with a user object. 53 | passport.use(new GitHubStrategy({ 54 | clientID: githubClient.githubClientId, 55 | clientSecret: githubClient.githubClientSecret, 56 | callbackURL: githubClient.redirectUrl 57 | }, 58 | function (accessToken, refreshToken, profile, done) { 59 | const octokit = new Octokit({ 60 | auth: `token ${ accessToken }` 61 | }); 62 | 63 | octokit.orgs.listForAuthenticatedUser() 64 | .then((result) => { 65 | const organizations = result.data.map((organization) => organization.login.toLowerCase()); 66 | 67 | profile.organizations = organizations; 68 | 69 | if (allowedOrganization && organizations.indexOf(allowedOrganization) < 0) { 70 | return done(null, false, { 71 | message: `Only members of [${ allowedOrganization }](https://github.com/${ allowedOrganization }) can access application logs` 72 | }); 73 | } 74 | 75 | if (isArray(allowedUsers) && !isEmpty(allowedUsers) && allowedUsers.indexOf(profile.username) < 0) { 76 | return done(null, false, { message: `Only specified users can access application logs` }); 77 | } 78 | 79 | return done(null, profile); 80 | }); 81 | } 82 | )); 83 | 84 | const webPanel = express(); 85 | 86 | webPanel.set('views', __dirname + '/../../views'); 87 | webPanel.set('view engine', 'ejs'); 88 | webPanel.set('view engine', 'html'); 89 | webPanel.use(partials()); 90 | webPanel.use(bodyParser.urlencoded({ extended: true })); 91 | webPanel.use(bodyParser.json()); 92 | webPanel.use(methodOverride()); 93 | webPanel.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: false })); 94 | // Initialize Passport! Also use passport.session() middleware, to support 95 | // persistent login sessions (recommended). 96 | webPanel.use(passport.initialize()); 97 | webPanel.use(passport.session()); 98 | webPanel.use(flash()); 99 | webPanel.use(express.static(__dirname + '/../../public')); 100 | webPanel.use(coldDeck.expressLogger()); 101 | webPanel.use(errorHandler); 102 | 103 | webPanel.get('/', ensureAuthenticated, function (req, res) { 104 | // res.render('index.', { user: req.user }); 105 | res.sendFile(path.join(__dirname + '/../../public/kb-cd-ui/index.html')); 106 | }); 107 | 108 | webPanel.get('/user', ensureAuthenticated, function (req, res) { 109 | const user: KbUser = { 110 | displayName: req.user.displayName, 111 | emails: req.user.emails.map((emailObj) => emailObj.value), 112 | organizations: req.user.organizations, 113 | username: req.user.username, 114 | avatar: req.user.photos[ 0 ].value 115 | }; 116 | res.json(user); 117 | }); 118 | 119 | webPanel.get('/login', function (req, res) { 120 | const message = req.flash('error').map((msg) => marked(msg)); 121 | res.render('login.ejs', { user: req.user, message: message }); 122 | }); 123 | 124 | // GET /auth/github 125 | // Use passport.authenticate() as route middleware to authenticate the 126 | // request. The first step in GitHub authentication will involve redirecting 127 | // the user to github.com. After authorization, GitHub will redirect the user 128 | // back to this application at /auth/github/callback 129 | webPanel.get('/auth/github', passport.authenticate('github', { scope: [ 'user:email', 'read:org' ] })); 130 | 131 | // GET /auth/github/callback 132 | // Use passport.authenticate() as route middleware to authenticate the 133 | // request. If authentication fails, the user will be redirected back to the 134 | // login page. Otherwise, the primary route function will be called, 135 | // which, in this example, will redirect the user to the home page. 136 | webPanel.get('/auth/github/callback', 137 | passport.authenticate('github', { 138 | successRedirect: '../../', 139 | failureFlash: true, 140 | failureRedirect: '../../login' 141 | })); 142 | 143 | webPanel.get('/logout', function (req, res) { 144 | req.logout(); 145 | res.redirect('/'); 146 | }); 147 | 148 | webPanel.get('/logs', function (req, res, next) { 149 | const day = moment.utc().format('YYYY-MM-DD'); 150 | const adapter = new FileAsync(process.cwd() + `/logs/${ day }.json`); 151 | 152 | fs.ensureFile(process.cwd() + `/logs/${ day }.json`) 153 | .then(() => lowdb(adapter)) 154 | .then((db) => { 155 | // send this day's database 156 | const todaysLogs = db.getState(); 157 | 158 | res.json(todaysLogs); 159 | 160 | // we later need to also open a web-socket channel to update for changes in today's logs' wdb 161 | }) 162 | .catch((err) => next(err)); 163 | // fs.readFile(process.cwd() + '/logs/combined.log', 'utf8', (err, fileContent) => { 164 | // if (err) { return next(err); } 165 | 166 | // try { 167 | // const logs = compact(fileContent.split('\n')).map((json) => JSON.parse(json)); 168 | // res.json({ logs }); 169 | // } catch (err) { 170 | // next(err); 171 | // } 172 | // }); 173 | }); 174 | 175 | webPanel.get('*', function (req, res) { 176 | res.status(404); 177 | res.render('error.ejs', { error: `the page you are looking for can't be found`, statusCode: 404 }); 178 | }); 179 | 180 | // app.listen(3000); 181 | 182 | return webPanel; 183 | 184 | 185 | // Simple route middleware to ensure user is authenticated. 186 | // Use this route middleware on any resource that needs to be protected. If 187 | // the request is authenticated (typically via a persistent login session), 188 | // the request will proceed. Otherwise, the user will be redirected to the 189 | // login page. 190 | function ensureAuthenticated(req, res, next) { 191 | if (req.isAuthenticated()) { return next(); } 192 | res.redirect('./login'); 193 | } 194 | 195 | function errorHandler(err, req, res, next) { 196 | res.status(500); 197 | res.render('error.ejs', { error: err, statusCode: 500 }); 198 | } 199 | 200 | }; 201 | --------------------------------------------------------------------------------