authmaker-common
Advanced tools
Comparing version 1.0.3 to 2.0.0
@@ -7,4 +7,4 @@ var mongoose = require('mongoose'); | ||
module.exports = { | ||
init: require('./lib/init'), | ||
models: require('./models') | ||
init: require('./lib/mongo').init, | ||
getModel: require('./models').getModel | ||
}; | ||
@@ -11,0 +11,0 @@ |
@@ -38,2 +38,2 @@ var Q = require('q'); | ||
}); | ||
} | ||
}; |
@@ -8,3 +8,3 @@ var mongoose = require('mongoose'); | ||
var accountSchema = new mongoose.Schema({ | ||
var schema = new mongoose.Schema({ | ||
stripeId: String, | ||
@@ -29,3 +29,3 @@ name: String, | ||
accountSchema.methods.getPlans = function() { | ||
schema.methods.getPlans = function() { | ||
@@ -43,3 +43,3 @@ return Q.ninvoke(this, 'populate', 'plans').then(function(account) { | ||
accountSchema.methods.setPlanExpiryDate = function(planName, expiryDate) { | ||
schema.methods.setPlanExpiryDate = function(planName, expiryDate) { | ||
@@ -126,7 +126,11 @@ winston.info("Updating account plan", { | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, accountSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ var mongoose = require('mongoose'); | ||
var auditTrailSchema = mongoose.Schema({ | ||
var schema = mongoose.Schema({ | ||
access_token: String, | ||
@@ -13,7 +13,11 @@ tag: String, | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, auditTrailSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ var mongoose = require('mongoose'); | ||
var externalIdentitySchema = mongoose.Schema({ | ||
var schema = mongoose.Schema({ | ||
externalId: String, | ||
@@ -15,7 +15,11 @@ username: String, | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, externalIdentitySchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
var fs = require('fs'); | ||
var path = require('path'); | ||
var Q = require('q'); | ||
@@ -18,2 +19,15 @@ var models = {}; | ||
function getModel(modelName) { | ||
return Q.fcall(function(){ | ||
var required = require('./' + modelName); | ||
if(!required){ | ||
throw new Error("Model " + modelName + " does not exist"); | ||
} | ||
return required.getModel(); | ||
}); | ||
} | ||
module.exports = models; | ||
module.exports.getModel = getModel; |
var mongoose = require('mongoose'); | ||
var modelName = 'Lead'; | ||
var leadSchema = new mongoose.Schema({ | ||
var schema = new mongoose.Schema({ | ||
data: mongoose.Schema.Types.Mixed | ||
}); | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, leadSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ var mongoose = require('mongoose'); | ||
var oauthClientSchema = new mongoose.Schema({ | ||
var schema = new mongoose.Schema({ | ||
name: String, | ||
@@ -19,7 +19,11 @@ client_id: String, | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, oauthClientSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ var mongoose = require('mongoose'); | ||
var oauthSessionSchema = mongoose.Schema({ | ||
var schema = mongoose.Schema({ | ||
access_token: String, | ||
@@ -18,7 +18,11 @@ client_id: String, | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, oauthSessionSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ var mongoose = require('mongoose'); | ||
var planSchema = new mongoose.Schema({ | ||
var schema = new mongoose.Schema({ | ||
name: String, | ||
@@ -18,6 +18,11 @@ stripePlan: String, | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, planSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ var mongoose = require('mongoose'); | ||
var scopeSchema = new mongoose.Schema({ | ||
var schema = new mongoose.Schema({ | ||
name: String, | ||
@@ -14,7 +14,11 @@ scope: String, | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, scopeSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
@@ -0,3 +1,3 @@ | ||
var _ = require('lodash'); | ||
var mongoose = require('mongoose'); | ||
var _ = require('lodash'); | ||
var Q = require('q'); | ||
@@ -7,3 +7,3 @@ | ||
var userSchema = new mongoose.Schema({ | ||
var schema = new mongoose.Schema({ | ||
@@ -88,7 +88,7 @@ /** | ||
userSchema.index({ | ||
schema.index({ | ||
username: 1 | ||
}); | ||
userSchema.index({ | ||
schema.index({ | ||
username: 1, | ||
@@ -100,3 +100,3 @@ clientId: 1 | ||
userSchema.methods.getAccounts = function() { | ||
schema.methods.getAccounts = function() { | ||
//return a (promise for) list of accounts that this user is a part of | ||
@@ -107,2 +107,4 @@ return this.model('Account').find({ | ||
var promises = accounts.map(function(account){ | ||
if(!account.plan) return Q(account); | ||
return account.plan.populate('scopes').execPopulate().then(function(){ | ||
@@ -113,7 +115,9 @@ return account; | ||
return Q.all(promises); | ||
return Q.all(promises).then(function(accounts){ | ||
return _.compact(accounts); | ||
}); | ||
}); | ||
}; | ||
userSchema.methods.getActiveScopes = function() { | ||
schema.methods.getActiveScopes = function() { | ||
return this.getAccounts().then(function(accounts) { | ||
@@ -134,7 +138,11 @@ return _(accounts) | ||
//protect against re-defining | ||
if (mongoose.modelNames().indexOf(modelName) !== -1) { | ||
module.exports.modelObject = mongoose.model(modelName); | ||
} else { | ||
module.exports.modelObject = mongoose.model(modelName, userSchema); | ||
} | ||
module.exports.getModel = function(){ | ||
return require(__dirname + '/../lib/mongo').getConnection().then(function(connection){ | ||
//protect against re-defining | ||
if (connection.modelNames().indexOf(modelName) !== -1) { | ||
return connection.model(modelName); | ||
} else { | ||
return connection.model(modelName, schema); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "authmaker-common", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Common aspects for all authmaker repos", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "NODE_ENV=test mocha --recursive --reporter spec", | ||
"test-watch": "npm run test -- -w --reporter min" | ||
}, | ||
@@ -25,3 +26,12 @@ "repository": { | ||
"winston": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"commander": "^2.9.0", | ||
"mocha": "^2.2.5", | ||
"nconf": "^0.8.2", | ||
"q": "^1.4.1", | ||
"sinon": "^1.15.4", | ||
"supertest": "^1.0.1" | ||
} | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
32985
23
969
0
7
15