models: move Application LDL def into a json file
Move some of the comments describing properties into jsdoc.
This commit is contained in:
parent
551d109a20
commit
1e6beabbd2
|
@ -1,95 +1,5 @@
|
||||||
var loopback = require('../../lib/loopback');
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
// Authentication schemes
|
|
||||||
var AuthenticationSchemeSchema = {
|
|
||||||
scheme: String, // local, facebook, google, twitter, linkedin, github
|
|
||||||
credential: Object // Scheme-specific credentials
|
|
||||||
};
|
|
||||||
|
|
||||||
// See https://github.com/argon/node-apn/blob/master/doc/apn.markdown
|
|
||||||
var APNSSettingSchema = {
|
|
||||||
/**
|
|
||||||
* production or development mode. It denotes what default APNS servers to be
|
|
||||||
* used to send notifications
|
|
||||||
* - true (production mode)
|
|
||||||
* - push: gateway.push.apple.com:2195
|
|
||||||
* - feedback: feedback.push.apple.com:2196
|
|
||||||
* - false (development mode, the default)
|
|
||||||
* - push: gateway.sandbox.push.apple.com:2195
|
|
||||||
* - feedback: feedback.sandbox.push.apple.com:2196
|
|
||||||
*/
|
|
||||||
production: Boolean,
|
|
||||||
certData: String, // The certificate data loaded from the cert.pem file
|
|
||||||
keyData: String, // The key data loaded from the key.pem file
|
|
||||||
|
|
||||||
pushOptions: {type: {
|
|
||||||
gateway: String,
|
|
||||||
port: Number
|
|
||||||
}},
|
|
||||||
|
|
||||||
feedbackOptions: {type: {
|
|
||||||
gateway: String,
|
|
||||||
port: Number,
|
|
||||||
batchFeedback: Boolean,
|
|
||||||
interval: Number
|
|
||||||
}}
|
|
||||||
};
|
|
||||||
|
|
||||||
var GcmSettingsSchema = {
|
|
||||||
serverApiKey: String
|
|
||||||
};
|
|
||||||
|
|
||||||
// Push notification settings
|
|
||||||
var PushNotificationSettingSchema = {
|
|
||||||
apns: APNSSettingSchema,
|
|
||||||
gcm: GcmSettingsSchema
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Data model for Application
|
|
||||||
*/
|
|
||||||
var ApplicationSchema = {
|
|
||||||
id: {type: String, id: true},
|
|
||||||
// Basic information
|
|
||||||
name: {type: String, required: true}, // The name
|
|
||||||
description: String, // The description
|
|
||||||
icon: String, // The icon image url
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
// EMail
|
|
||||||
email: String, // e-mail address
|
|
||||||
emailVerified: Boolean, // Is the e-mail verified
|
|
||||||
|
|
||||||
// oAuth 2.0 settings
|
|
||||||
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
|
|
||||||
clientKey: String,
|
|
||||||
javaScriptKey: String,
|
|
||||||
restApiKey: String,
|
|
||||||
windowsKey: String,
|
|
||||||
masterKey: String,
|
|
||||||
|
|
||||||
// Push notification
|
|
||||||
pushSettings: PushNotificationSettingSchema,
|
|
||||||
|
|
||||||
// User Authentication
|
|
||||||
authenticationEnabled: {type: Boolean, default: true},
|
|
||||||
anonymousAllowed: {type: Boolean, default: true},
|
|
||||||
authenticationSchemes: [AuthenticationSchemeSchema],
|
|
||||||
|
|
||||||
status: {type: String, default: 'sandbox'}, // Status of the application, production/sandbox/disabled
|
|
||||||
|
|
||||||
// Timestamps
|
|
||||||
created: {type: Date, default: Date},
|
|
||||||
modified: {type: Date, default: Date}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Application management functions
|
* Application management functions
|
||||||
*/
|
*/
|
||||||
|
@ -123,6 +33,9 @@ function generateKey(hmacKey, algorithm, encoding) {
|
||||||
* @property {Date} created Date Application object was created. Default: current date.
|
* @property {Date} created Date Application object was created. Default: current date.
|
||||||
* @property {Date} modified Date Application object was modified. Default: current date.
|
* @property {Date} modified Date Application object was modified. Default: current date.
|
||||||
*
|
*
|
||||||
|
* @property {Object} pushSettings.apns APNS configuration, see the options
|
||||||
|
* below and also
|
||||||
|
* https://github.com/argon/node-apn/blob/master/doc/apn.markdown
|
||||||
* @property {Boolean} pushSettings.apns.production Whether to use production Apple Push Notification Service (APNS) servers to send push notifications.
|
* @property {Boolean} pushSettings.apns.production Whether to use production Apple Push Notification Service (APNS) servers to send push notifications.
|
||||||
* If true, uses `gateway.push.apple.com:2195` and `feedback.push.apple.com:2196`.
|
* If true, uses `gateway.push.apple.com:2195` and `feedback.push.apple.com:2196`.
|
||||||
* If false, uses `gateway.sandbox.push.apple.com:2195` and `feedback.sandbox.push.apple.com:2196`
|
* If false, uses `gateway.sandbox.push.apple.com:2195` and `feedback.sandbox.push.apple.com:2196`
|
||||||
|
@ -136,17 +49,39 @@ function generateKey(hmacKey, algorithm, encoding) {
|
||||||
* @property {Number} pushSettings.apns.feedbackOptions.interval (APNS).
|
* @property {Number} pushSettings.apns.feedbackOptions.interval (APNS).
|
||||||
* @property {String} pushSettings.gcm.serverApiKey: Google Cloud Messaging API key.
|
* @property {String} pushSettings.gcm.serverApiKey: Google Cloud Messaging API key.
|
||||||
*
|
*
|
||||||
* @class
|
* @property {Boolean} authenticationEnabled
|
||||||
* @inherits {Model}
|
* @property {Boolean} anonymousAllowed
|
||||||
|
* @property {Array} authenticationSchemes List of authentication schemes
|
||||||
|
* (see below).
|
||||||
|
* @property {String} authenticationSchemes.scheme Scheme name.
|
||||||
|
* Supported values: `local`, `facebook`, `google`,
|
||||||
|
* `twitter`, `linkedin`, `github`.
|
||||||
|
* @property {Object} authenticationSchemes.credential
|
||||||
|
* Scheme-specific credentials.
|
||||||
|
*
|
||||||
|
* @class Application
|
||||||
|
* @inherits {PersistedModel}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Application = loopback.PersistedModel.extend('Application', ApplicationSchema);
|
module.exports = function(Application) {
|
||||||
|
|
||||||
/*!
|
// Workaround for https://github.com/strongloop/loopback/issues/292
|
||||||
|
Application.definition.rawProperties.created.default =
|
||||||
|
Application.definition.properties.created.default = function() {
|
||||||
|
return new Date();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Workaround for https://github.com/strongloop/loopback/issues/292
|
||||||
|
Application.definition.rawProperties.modified.default =
|
||||||
|
Application.definition.properties.modified.default = function() {
|
||||||
|
return new Date();
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
* A hook to generate keys before creation
|
* A hook to generate keys before creation
|
||||||
* @param next
|
* @param next
|
||||||
*/
|
*/
|
||||||
Application.beforeCreate = function (next) {
|
Application.beforeCreate = function(next) {
|
||||||
var app = this;
|
var app = this;
|
||||||
app.created = app.modified = new Date();
|
app.created = app.modified = new Date();
|
||||||
app.id = generateKey('id', 'md5');
|
app.id = generateKey('id', 'md5');
|
||||||
|
@ -156,16 +91,16 @@ Application.beforeCreate = function (next) {
|
||||||
app.windowsKey = generateKey('windows');
|
app.windowsKey = generateKey('windows');
|
||||||
app.masterKey = generateKey('master');
|
app.masterKey = generateKey('master');
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new application
|
* Register a new application
|
||||||
* @param {String} owner Owner's user ID.
|
* @param {String} owner Owner's user ID.
|
||||||
* @param {String} name Name of the application
|
* @param {String} name Name of the application
|
||||||
* @param {Object} options Other options
|
* @param {Object} options Other options
|
||||||
* @param {Function} callback Callback function
|
* @param {Function} callback Callback function
|
||||||
*/
|
*/
|
||||||
Application.register = function (owner, name, options, cb) {
|
Application.register = function(owner, name, options, cb) {
|
||||||
assert(owner, 'owner is required');
|
assert(owner, 'owner is required');
|
||||||
assert(name, 'name is required');
|
assert(name, 'name is required');
|
||||||
|
|
||||||
|
@ -180,14 +115,14 @@ Application.register = function (owner, name, options, cb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.create(props, cb);
|
this.create(props, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset keys for the application instance
|
* Reset keys for the application instance
|
||||||
* @callback {Function} callback
|
* @callback {Function} callback
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
*/
|
*/
|
||||||
Application.prototype.resetKeys = function (cb) {
|
Application.prototype.resetKeys = function(cb) {
|
||||||
this.clientKey = generateKey('client');
|
this.clientKey = generateKey('client');
|
||||||
this.javaScriptKey = generateKey('javaScript');
|
this.javaScriptKey = generateKey('javaScript');
|
||||||
this.restApiKey = generateKey('restApi');
|
this.restApiKey = generateKey('restApi');
|
||||||
|
@ -195,25 +130,25 @@ Application.prototype.resetKeys = function (cb) {
|
||||||
this.masterKey = generateKey('master');
|
this.masterKey = generateKey('master');
|
||||||
this.modified = new Date();
|
this.modified = new Date();
|
||||||
this.save(cb);
|
this.save(cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset keys for a given application by the appId
|
* Reset keys for a given application by the appId
|
||||||
* @param {Any} appId
|
* @param {Any} appId
|
||||||
* @callback {Function} callback
|
* @callback {Function} callback
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
*/
|
*/
|
||||||
Application.resetKeys = function (appId, cb) {
|
Application.resetKeys = function(appId, cb) {
|
||||||
this.findById(appId, function (err, app) {
|
this.findById(appId, function(err, app) {
|
||||||
if (err) {
|
if (err) {
|
||||||
cb && cb(err, app);
|
cb && cb(err, app);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
app.resetKeys(cb);
|
app.resetKeys(cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate the application id and key.
|
* Authenticate the application id and key.
|
||||||
*
|
*
|
||||||
* `matched` parameter is one of:
|
* `matched` parameter is one of:
|
||||||
|
@ -229,8 +164,8 @@ Application.resetKeys = function (appId, cb) {
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
* @param {String} matched The matching key
|
* @param {String} matched The matching key
|
||||||
*/
|
*/
|
||||||
Application.authenticate = function (appId, key, cb) {
|
Application.authenticate = function(appId, key, cb) {
|
||||||
this.findById(appId, function (err, app) {
|
this.findById(appId, function(err, app) {
|
||||||
if (err || !app) {
|
if (err || !app) {
|
||||||
cb && cb(err, null);
|
cb && cb(err, null);
|
||||||
return;
|
return;
|
||||||
|
@ -248,7 +183,5 @@ Application.authenticate = function (appId, key, cb) {
|
||||||
}
|
}
|
||||||
cb && cb(null, result);
|
cb && cb(null, result);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Application;
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
{
|
||||||
|
"name": "Application",
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string",
|
||||||
|
"id": true
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"description": "string",
|
||||||
|
"icon": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The icon image url"
|
||||||
|
},
|
||||||
|
|
||||||
|
"owner": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The user id of the developer who registers the application"
|
||||||
|
},
|
||||||
|
"collaborators": {
|
||||||
|
"type": ["string"],
|
||||||
|
"description": "A list of users ids who have permissions to work on this app"
|
||||||
|
},
|
||||||
|
|
||||||
|
"email": "string",
|
||||||
|
"emailVerified": "boolean",
|
||||||
|
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The application URL for OAuth 2.0"
|
||||||
|
},
|
||||||
|
"callbackUrls": {
|
||||||
|
"type": ["string"],
|
||||||
|
"description": "OAuth 2.0 code/token callback URLs"
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"type": ["string"],
|
||||||
|
"description": "A list of permissions required by the application"
|
||||||
|
},
|
||||||
|
|
||||||
|
"clientKey": "string",
|
||||||
|
"javaScriptKey": "string",
|
||||||
|
"restApiKey": "string",
|
||||||
|
"windowsKey": "string",
|
||||||
|
"masterKey": "string",
|
||||||
|
|
||||||
|
"pushSettings": {
|
||||||
|
"apns": {
|
||||||
|
"production": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": [
|
||||||
|
"Production or development mode. It denotes what default APNS",
|
||||||
|
"servers to be used to send notifications.",
|
||||||
|
"See API documentation for more details."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
"certData": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The certificate data loaded from the cert.pem file"
|
||||||
|
},
|
||||||
|
"keyData": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The key data loaded from the key.pem file"
|
||||||
|
},
|
||||||
|
|
||||||
|
"pushOptions": {
|
||||||
|
"type": {
|
||||||
|
"gateway": "string",
|
||||||
|
"port": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"feedbackOptions": {
|
||||||
|
"type": {
|
||||||
|
"gateway": "string",
|
||||||
|
"port": "number",
|
||||||
|
"batchFeedback": "boolean",
|
||||||
|
"interval": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"gcm": {
|
||||||
|
"serverApiKey": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"authenticationEnabled": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"anonymousAllowed": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"authenticationSchemes": [
|
||||||
|
{
|
||||||
|
"scheme": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "See the API docs for the list of supported values."
|
||||||
|
},
|
||||||
|
"credential": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Scheme-specific credentials"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "sandbox",
|
||||||
|
"description": "Status of the application, production/sandbox/disabled"
|
||||||
|
},
|
||||||
|
|
||||||
|
"created": "date",
|
||||||
|
"modified": "date"
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,10 @@ module.exports = function(loopback) {
|
||||||
require('../common/models/email.json'),
|
require('../common/models/email.json'),
|
||||||
require('../common/models/email.js'));
|
require('../common/models/email.js'));
|
||||||
|
|
||||||
loopback.Application = require('../common/models/application');
|
loopback.Application = createModel(
|
||||||
|
require('../common/models/application.json'),
|
||||||
|
require('../common/models/application.js'));
|
||||||
|
|
||||||
loopback.AccessToken = require('../common/models/access-token');
|
loopback.AccessToken = require('../common/models/access-token');
|
||||||
loopback.Role = require('../common/models/role').Role;
|
loopback.Role = require('../common/models/role').Role;
|
||||||
loopback.RoleMapping = require('../common/models/role').RoleMapping;
|
loopback.RoleMapping = require('../common/models/role').RoleMapping;
|
||||||
|
|
Loading…
Reference in New Issue