Commit c4d45548 authored by anton's avatar anton

Initial skeleton

parents
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2018
},
env: {
node: true,
es6: true,
mocha: true
},
settings: {
flowtype: {
onlyFilesWithFlowAnnotation: true
}
},
extends: [
'standard',
'plugin:flowtype/recommended'
],
plugins: [
'flowtype'
],
// add your custom rules here
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow paren-less arrow functions
'arrow-parens': 'off',
'one-var': 'off',
'import/first': 'off',
'import/named': 'error',
'import/namespace': 'error',
'import/default': 'error',
'import/export': 'error',
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',
'prefer-promise-reject-errors': 'off',
// allow debugger during development only
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'brace-style': [2, 'stroustrup', { 'allowSingleLine': true }],
// change default indent behaviour
'indent': 'off',
'indent-legacy': ['error', 2]
}
}
# Node.js
node_modules
bower_components
*.log
*.db
*.nedb
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
cmake-build-release/
# NAPI
build/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Book build output
_book
# eBook build output
*.epub
*.mobi
*.pdf
# JetBrains
.idea
# nyc coverage
.nyc_output
# Quasar
.quasar
/src-cordova/platforms
/src-cordova/plugins
/src-cordova/www
10.16.3
## Docker
[![](https://images.microbadger.com/badges/image/motionbank/api.svg)](https://microbadger.com/images/motionbank/api "Get your own image badge on microbadger.com")
The docker image can be pulled with the tag `motionbank/api:latest`.
The MIT License (MIT)
Copyright © 2018 Mainz University of Applied Sciences (Motion Bank Project)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[comment]: # (ACHTUNG! This is an autogenerated file and will be automatically overwritten)
[comment]: # (To edit its contents please refer to the project dir '.readme')
# @motionbank/api
> API for Motion Bank Systems
## Docker
[![](https://images.microbadger.com/badges/image/motionbank/api.svg)](https://microbadger.com/images/motionbank/api "Get your own image badge on microbadger.com")
The docker image can be pulled with the tag `motionbank/api:latest`.
## License
:copyright: 2020 Mainz University of Applied Sciences (Motion Bank Project) –
Released under the [MIT](https://github.com/motionbank-js/@motionbank/api/blob/master/LICENSE) license
{
"host": "localhost",
"port": 3030,
"public": "../public/",
"paginate": {
"default": 10,
"max": 50
},
"authentication": {
"entity": "user",
"service": "users",
"secret": "M5Q6+pXQrAHKlwGz9v/fSw0mIGo=",
"authStrategies": [
"jwt",
"local"
],
"jwtOptions": {
"header": {
"typ": "access"
},
"audience": "https://yourdomain.com",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"usernameField": "email",
"passwordField": "password"
},
"oauth": {
"redirect": "/",
"auth0": {
"key": "<auth0 oauth key>",
"secret": "<auth0 oauth secret>",
"subdomain": "<auth0 subdomain>"
}
}
},
"mongodb": "mongodb://localhost:27017/motionbank_api",
"nedb": "../data"
}
{
"host": "motionbank-api-app.feathersjs.com",
"port": "PORT"
}
This diff is collapsed.
{
"name": "@motionbank/api",
"description": "API for Motion Bank Systems",
"version": "3.0.0-alpha-0",
"homepage": "",
"private": true,
"main": "src/api-local.js",
"keywords": [
"feathers"
],
"author": "Mainz University of Applied Sciences (Motion Bank Project)",
"contributors": [],
"bugs": {},
"metapak": {
"configs": [
"readme"
]
},
"directories": {
"lib": "src",
"test": "test/",
"config": "config/"
},
"engines": {
"node": "^12.0.0",
"npm": ">= 3.0.0"
},
"scripts": {
"dev": "nodemon src/",
"lint": "eslint src/. test/.",
"metapak": "metapak",
"mocha": "mocha test/ --recursive --exit",
"start": "node src/",
"test": "npm run lint && npm run mocha"
},
"standard": {
"env": [
"mocha"
],
"ignore": []
},
"dependencies": {
"@feathersjs/authentication": "^4.5.2",
"@feathersjs/authentication-local": "^4.5.2",
"@feathersjs/authentication-oauth": "^4.5.2",
"@feathersjs/configuration": "^4.5.2",
"@feathersjs/errors": "^4.5.2",
"@feathersjs/express": "^4.5.2",
"@feathersjs/feathers": "^4.5.2",
"@feathersjs/primus": "^4.5.2",
"@feathersjs/transport-commons": "^4.5.2",
"compression": "^1.7.4",
"cors": "^2.8.5",
"feathers-mongodb": "^6.1.0",
"feathers-mongoose": "^8.3.0",
"feathers-nedb": "^5.1.0",
"helmet": "^3.21.3",
"mbjs-data-models": "^2.0.13",
"mongodb": "^3.5.5",
"mongodb-core": "^3.2.7",
"mongoose": "^5.9.5",
"nedb": "^1.8.0",
"serve-favicon": "^2.5.0",
"winston": "^3.2.1",
"ws": "^7.2.3"
},
"devDependencies": {
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-flowtype": "^4.6.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"flow-bin": "^0.120.1",
"metapak": "^1.0.3",
"metapak-motionbank": "^1.16.0",
"mocha": "^7.1.0",
"nodemon": "^2.0.2"
},
"license": "MIT"
}
#!/bin/sh
# Automagically generated by metapak, do not change in place.
# Your changes would be loose on the next npm install run.
npm run lint || exit 0;
npm run metapak -- -s || exit 0
\ No newline at end of file
This diff is collapsed.
const feathers = require('@feathersjs/feathers')
const services = require('./services')
const appHooks = require('./app.hooks')
const factory = function (configuration = {}) {
const app = feathers()
// Apply app configuration
app.configure(app => {
const keys = Object.keys(configuration)
for (const key of keys) {
app.set(key, configuration[key])
}
})
// Set up our services (see `services/index.js`)
app.configure(services)
app.hooks(appHooks)
return app
}
module.exports = factory
// Application hooks that run for every service
module.exports = {
before: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
}
const path = require('path')
const favicon = require('serve-favicon')
const compress = require('compression')
const helmet = require('helmet')
const cors = require('cors')
const logger = require('./logger')
const feathers = require('@feathersjs/feathers')
const configuration = require('@feathersjs/configuration')
const express = require('@feathersjs/express')
const primus = require('@feathersjs/primus')
const middleware = require('./middleware')
const services = require('./services')
const appHooks = require('./app.hooks')
const channels = require('./channels')
const authentication = require('./authentication')
const mongoose = require('./mongoose')
const mongodb = require('./mongodb')
const app = express(feathers())
// Load app configuration
app.configure(configuration())
// Enable security, CORS, compression, favicon and body parsing
app.use(helmet())
app.use(cors())
app.use(compress())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(favicon(path.join(app.get('public'), 'favicon.ico')))
// Host the public folder
app.use('/', express.static(app.get('public')))
// Set up Plugins and providers
app.configure(express.rest())
app.configure(primus({ transformer: 'websockets' }))
app.configure(mongoose)
app.configure(mongodb)
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware)
app.configure(authentication)
// Set up our services (see `services/index.js`)
app.configure(services)
// Set up event channels (see channels.js)
app.configure(channels)
// Configure a middleware for 404s and the error handler
app.use(express.notFound())
app.use(express.errorHandler({ logger }))
app.hooks(appHooks)
module.exports = app
const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication')
const { LocalStrategy } = require('@feathersjs/authentication-local')
const { expressOauth } = require('@feathersjs/authentication-oauth')
module.exports = app => {
const authentication = new AuthenticationService(app)
authentication.register('jwt', new JWTStrategy())
authentication.register('local', new LocalStrategy())
app.use('/authentication', authentication)
app.configure(expressOauth())
}
module.exports = function (app) {
if (typeof app.channel !== 'function') {
// If no real-time functionality has been configured just return
return
}
app.on('connection', connection => {
// On a new real-time connection, add it to the anonymous channel
app.channel('anonymous').join(connection)
})
app.on('login', (authResult, { connection }) => {
// connection can be undefined if there is no
// real-time connection, e.g. when logging in via REST
if (connection) {
// Obtain the logged in user from the connection
// const user = connection.user;
// The connection is no longer anonymous, remove it
app.channel('anonymous').leave(connection)
// Add it to the authenticated user channel
app.channel('authenticated').join(connection)
// Channels can be named anything and joined on any condition
// E.g. to send real-time events only to admins use
// if(user.isAdmin) { app.channel('admins').join(connection); }
// If the user has joined e.g. chat rooms
// if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(channel));
// Easily organize users by email and userid for things like messaging
// app.channel(`emails/${user.email}`).join(channel);
// app.channel(`userIds/$(user.id}`).join(channel);
}
})
// eslint-disable-next-line no-unused-vars
app.publish((data, hook) => {
// Here you can add event publishers to channels set up in `channels.js`
// To publish only for a specific event use `app.publish(eventname, () => {})`
console.log('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line
// e.g. to publish all service events to all authenticated users use
return app.channel('authenticated')
})
// Here you can also add service specific event publishers
// e.g. the publish the `users` service `created` event to the `admins` channel
// app.service('users').publish('created', () => app.channel('admins'));
// With the userid and email organization from above you can easily select involved users
// app.service('messages').publish(() => {
// return [
// app.channel(`userIds/${data.createdBy}`),
// app.channel(`emails/${data.recipientEmail}`)
// ];
// });
}
/* eslint-disable no-console */
const logger = require('./logger')
const app = require('./app')
const port = app.get('port')
const server = app.listen(port)
process.on('unhandledRejection', (reason, p) =>
logger.error('Unhandled Rejection at: Promise ', p, reason)
)
server.on('listening', () =>
logger.info('Feathers application started on http://%s:%d', app.get('host'), port)
)
const { createLogger, format, transports } = require('winston')
// Configure the Winston logger. For the complete documentation see https://github.com/winstonjs/winston
const logger = createLogger({
// To see more detailed errors, change this to 'debug'
level: 'info',
format: format.combine(
format.splat(),
format.simple()
),
transports: [
new transports.Console()
]
})
module.exports = logger
// eslint-disable-next-line no-unused-vars
module.exports = function (app) {
// Add your custom middleware here. Remember that
// in Express, the order matters.
}
// users-model.js - A mongoose model
//
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
module.exports = function (app) {
const modelName = 'users'
const mongooseClient = app.get('mongooseClient')
const schema = new mongooseClient.Schema({
email: { type: String, unique: true, lowercase: true },
password: { type: String },
auth0Id: { type: String }
}, {
timestamps: true
})
// This is necessary to avoid model compilation errors in watch mode
// see https://mongoosejs.com/docs/api/connection.html#connection_Connection-deleteModel
if (mongooseClient.modelNames().includes(modelName)) {
mongooseClient.deleteModel(modelName)
}
return mongooseClient.model(modelName, schema)
}
const MongoClient = require('mongodb').MongoClient
module.exports = function (app) {
const connection = app.get('mongodb')
const database = connection.substr(connection.lastIndexOf('/') + 1)
const mongoClient = MongoClient.connect(connection, { useNewUrlParser: true })
.then(client => client.db(database))
app.set('mongoClient', mongoClient)
}
const mongoose = require('mongoose')
const logger = require('./logger')
module.exports = function (app) {
mongoose.connect(
app.get('mongodb'),
{ useCreateIndex: true, useNewUrlParser: true }
).catch(err => {
logger.error(err)
process.exit(1)
})
mongoose.Promise = global.Promise
app.set('mongooseClient', mongoose)
}
const { authenticate } = require('@feathersjs/authentication').hooks
module.exports = function (app) {
const hooks = {
before: {
all: [authenticate('jwt')],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
}
if (app.get('nedb')) hooks.before.all = []
return hooks
}
// Initializes the `annotations` service on path `/annotations`
const hooks = require('./annotations.hooks')
const conditionalDbService = require('../conditional-db-service')
module.exports = function (app) {
const options = {
paginate: app.get('paginate')
}
const Annotations = conditionalDbService(app, 'annotations')
app.use('/annotations', new Annotations(options, app))
// Get our initialized service so that we can register hooks
const service = app.service('annotations')
service.hooks(hooks(!app.get('host')))
}
const conditionalDbService = function (app, name) {
if (app.get('mongoClient')) {
const { Service } = require('feathers-mongodb')
class MongoService extends Service {
constructor (options, app) {
super(options)
app.get('mongoClient').then(db => {
this.Model = db.collection(name)
})
}
}
return MongoService
}