Add exports to models
This commit is contained in:
parent
b4391e6b26
commit
83ca45e07e
|
@ -39,7 +39,13 @@ var ACLSchema = {
|
||||||
permission: {type: String, enum: ['Allow', 'Deny']}, // Allow/Deny
|
permission: {type: String, enum: ['Allow', 'Deny']}, // Allow/Deny
|
||||||
status: String, // Enabled/disabled
|
status: String, // Enabled/disabled
|
||||||
created: Date,
|
created: Date,
|
||||||
lastUpdated: Date
|
modified: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
// readAccess, writeAccess --> public, userId, role
|
// readAccess, writeAccess --> public, userId, role
|
||||||
|
|
||||||
|
module.exports = function(dataSource) {
|
||||||
|
dataSource = dataSource || new require('jugglingdb').ModelBuilder();
|
||||||
|
var ACL = dataSource.define('ACL', ACLSchema);
|
||||||
|
return ACL;
|
||||||
|
}
|
|
@ -1,17 +1,26 @@
|
||||||
|
// Authentication schemes
|
||||||
|
var AuthenticationScheme = {
|
||||||
|
scheme: String, // local, facebook, google, twitter, linkedin, github
|
||||||
|
credential: Object // Scheme-specific credentials
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push notification settings
|
||||||
|
var PushNotificationSetting = {
|
||||||
|
platform: {type: String, required: true}, // apns, gcm, mpns
|
||||||
|
configuration: Object // platform-specific configurations
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data model for Application
|
* Data model for Application
|
||||||
*/
|
*/
|
||||||
var ApplicationSchema = {
|
var ApplicationSchema = {
|
||||||
|
|
||||||
// Basic information
|
// Basic information
|
||||||
id: {type: String, required: true},
|
id: {type: String, required: true}, // The id
|
||||||
name: {type: String, required: true},
|
name: {type: String, required: true}, // The name
|
||||||
description: String, // description
|
description: String, // The description
|
||||||
icon: String, // The icon image url
|
icon: String, // The icon image url
|
||||||
|
|
||||||
public: Boolean, // Do we list the application in the public catalog?
|
|
||||||
permissions: [String],
|
|
||||||
|
|
||||||
owner: String, // The user id of the developer who registers the application
|
owner: String, // The user id of the developer who registers the application
|
||||||
collaborators: [String], // A list of users ids who have permissions to work on this app
|
collaborators: [String], // A list of users ids who have permissions to work on this app
|
||||||
|
|
||||||
|
@ -19,8 +28,10 @@ var ApplicationSchema = {
|
||||||
email: String, // e-mail address
|
email: String, // e-mail address
|
||||||
emailVerified: Boolean, // Is the e-mail verified
|
emailVerified: Boolean, // Is the e-mail verified
|
||||||
|
|
||||||
|
// oAuth 2.0 settings
|
||||||
status: String, // Status of the application, enabled/disabled
|
url: String, // The application url
|
||||||
|
callbackUrls: [String], // oAuth 2.0 code/token callback url
|
||||||
|
permissions: [String], // A list of permissions required by the application
|
||||||
|
|
||||||
// Keys
|
// Keys
|
||||||
clientKey: String,
|
clientKey: String,
|
||||||
|
@ -30,18 +41,18 @@ var ApplicationSchema = {
|
||||||
masterKey: String,
|
masterKey: String,
|
||||||
|
|
||||||
// Push notification
|
// Push notification
|
||||||
pushPlatforms: [String],
|
pushSettings: [PushNotificationSetting],
|
||||||
pushCredentials: [],
|
|
||||||
|
|
||||||
// User Authentication
|
// User Authentication
|
||||||
authenticationEnabled: Boolean,
|
authenticationEnabled: {type: Boolean, default: true},
|
||||||
anonymousAllowed: Boolean,
|
anonymousAllowed: {type: Boolean, default: true},
|
||||||
schemes: [String], // Basic, facebook, github, google
|
authenticationSchemes: [AuthenticationScheme],
|
||||||
attachedCredentials: [],
|
|
||||||
|
|
||||||
|
status: {type: String, default: 'sandbox'}, // Status of the application, production/sandbox/disabled
|
||||||
|
|
||||||
created: Date,
|
// Timestamps
|
||||||
lastUpdated: Date
|
created: {type: Date, default: Date},
|
||||||
|
modified: {type: Date, default: Date}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +60,43 @@ var ApplicationSchema = {
|
||||||
* Application management functions
|
* Application management functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Register a new application
|
var crypto = require('crypto');
|
||||||
|
|
||||||
|
function generateKey(hmacKey, algorithm) {
|
||||||
|
hmacKey = hmacKey || 'asteroid';
|
||||||
|
algorithm = algorithm || 'sha256';
|
||||||
|
var hmac = crypto.createHmac(algorithm, hmacKey);
|
||||||
|
var buf = crypto.randomBytes(64);
|
||||||
|
hmac.update(buf);
|
||||||
|
return hmac.digest('base64');
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = function (dataSource) {
|
||||||
|
dataSource = dataSource || new require('jugglingdb').ModelBuilder();
|
||||||
|
|
||||||
|
|
||||||
|
var Application = dataSource.define('Application', ApplicationSchema);
|
||||||
|
|
||||||
|
Application.afterInitialize = function () {
|
||||||
|
var app = this;
|
||||||
|
// use data argument to update object
|
||||||
|
app.created = app.modified = new Date();
|
||||||
|
app.id = generateKey('id', 'sha1');
|
||||||
|
app.clientKey = generateKey('client');
|
||||||
|
app.javaScriptKey = generateKey('javaScript');
|
||||||
|
app.restApiKey = generateKey('restApi');
|
||||||
|
app.windowsKey = generateKey('windows');
|
||||||
|
app.masterKey = generateKey('master');
|
||||||
|
};
|
||||||
|
|
||||||
|
// Register a new application
|
||||||
|
Application.register = function (name, description, owner) {
|
||||||
|
return new Application({name: name, description: description, owner: owner});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Application;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
var ModelBuilder = require('jugglingdb').ModelBuilder;
|
||||||
|
|
||||||
|
var ds = new ModelBuilder();
|
||||||
|
|
||||||
|
exports.Application = require('./application')(ds);
|
||||||
|
exports.ACL = require('./acl')(ds);
|
||||||
|
exports.Role = require('./role')(ds);
|
||||||
|
exports.Installation = require('./installation')(ds);
|
||||||
|
|
||||||
|
/*
|
||||||
|
console.log(new exports.Role());
|
||||||
|
console.log(new exports.ACL());
|
||||||
|
console.log(new exports.Application());
|
||||||
|
console.log(new exports.Installation());
|
||||||
|
*/
|
||||||
|
|
|
@ -5,13 +5,22 @@ var InstallationSchema = {
|
||||||
required: true,
|
required: true,
|
||||||
id: 1
|
id: 1
|
||||||
},
|
},
|
||||||
appId: String,
|
appId: String, // Application id
|
||||||
appVersion: String,
|
appVersion: String, // Application version
|
||||||
userId: String,
|
userId: String, // User id
|
||||||
deviceToken: String,
|
deviceToken: String,
|
||||||
deviceType: String,
|
deviceType: String,
|
||||||
subscriptions: [String],
|
subscriptions: [String],
|
||||||
created: Date,
|
|
||||||
lastModified: Date,
|
status: {type: String, default: 'active'}, // Status of the application, production/sandbox/disabled
|
||||||
status: String
|
|
||||||
|
// Timestamps
|
||||||
|
created: {type: Date, default: Date},
|
||||||
|
modified: {type: Date, default: Date}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = function(dataSource) {
|
||||||
|
dataSource = dataSource || new require('jugglingdb').ModelBuilder();
|
||||||
|
var Installation = dataSource.define('Installation', InstallationSchema);
|
||||||
|
return Installation;
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
// Role model
|
// Role model
|
||||||
var RoleSchema = {
|
var RoleSchema = {
|
||||||
id: {type: String, required: true},
|
id: {type: String, required: true}, // Id
|
||||||
name: {type: String, required: true}, // The name of a role
|
name: {type: String, required: true}, // The name of a role
|
||||||
description: String,
|
description: String, // Description
|
||||||
roles: [String], // A role can be an aggregate of other roles
|
roles: [String], // A role can be an aggregate of other roles
|
||||||
users: [String], // A role contains a list of users
|
users: [String], // A role contains a list of user ids
|
||||||
created: Date,
|
|
||||||
lastUpdated: Date
|
// Timestamps
|
||||||
|
created: {type: Date, default: Date},
|
||||||
|
modified: {type: Date, default: Date}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = function(dataSource) {
|
||||||
|
dataSource = dataSource || new require('jugglingdb').ModelBuilder();
|
||||||
|
var Role = dataSource.define('Role', RoleSchema);
|
||||||
|
return Role;
|
||||||
}
|
}
|
|
@ -57,5 +57,5 @@ var UserSchema = {
|
||||||
*/
|
*/
|
||||||
status: String,
|
status: String,
|
||||||
created: Date,
|
created: Date,
|
||||||
lastUpdated: Date
|
modified: Date
|
||||||
}
|
}
|
Loading…
Reference in New Issue