diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..a6e5297
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,3 @@
+{
+ "extends": "loopback"
+}
\ No newline at end of file
diff --git a/.jshintignore b/.jshintignore
deleted file mode 100644
index 3f12ace..0000000
--- a/.jshintignore
+++ /dev/null
@@ -1,5 +0,0 @@
-bower_components/
-node_modules/
-coverage/
-karma.conf.js
-apidocs/loopback-core.js
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 77a36c8..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,24 +0,0 @@
-{
-"node": true,
-"browser": true,
-"camelcase" : true,
-"eqnull" : true,
-"indent": 2,
-"undef": true,
-"quotmark": "single",
-"maxlen": 80,
-"trailing": true,
-"newcap": true,
-"nonew": true,
-"sub": true,
-"globals": {
- "describe": true,
- "it": true,
- "before": true,
- "beforeEach": true,
- "after": true,
- "afterEach": true,
- "define": true,
- "expect": true
-}
-}
diff --git a/CHANGES.md b/CHANGES.md
index 708d983..cfddf92 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,23 @@
+2016-07-13, Version 1.8.0
+=========================
+
+ * Expose configured properties on LoopBackResource (Matteo Padovano)
+
+ * Describe model schema in generated $resource (Miroslav Bajtos)
+
+ * update copyright notices and license (Ryan Graham)
+
+ * Clear user data when logout returns error response (Matteo Padovano)
+
+ * Lint generated code (David Cheung)
+
+ * Use ESlint in replace of jshint (David Cheung)
+
+ * added test for LoopBackResourceProvider.getAuthHeader() method. (Martin Juhasz)
+
+ * Added getter for AuthHeader value in LoopBackResource (Martin Juhasz)
+
+
2016-02-24, Version 1.7.0
=========================
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index af14d6e..8ad9359 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -147,5 +147,5 @@ Contributing to `loopback-sdk-angular` is easy. In a few simple steps:
inaccurate in any respect. Email us at callback@strongloop.com.
```
-[Google C++ Style Guide]: https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
-[Google Javascript Style Guide]: https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
+[Google C++ Style Guide]: https://google.github.io/styleguide/cppguide.html
+[Google Javascript Style Guide]: https://google.github.io/styleguide/javascriptguide.xml
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..47a5d46
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) IBM Corp. 2014,2015. All Rights Reserved.
+Node module: loopback-sdk-angular
+This project is licensed under the MIT License, full text below.
+
+--------
+
+MIT license
+
+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.
diff --git a/LICENSE.md b/LICENSE.md
deleted file mode 100644
index 3702054..0000000
--- a/LICENSE.md
+++ /dev/null
@@ -1,9 +0,0 @@
-Copyright (c) 2013-2015 StrongLoop, Inc.
-
-loopback-sdk-angular uses a dual license model.
-
-You may use this library under the terms of the [MIT License][],
-or under the terms of the [StrongLoop Subscription Agreement][].
-
-[MIT License]: http://opensource.org/licenses/MIT
-[StrongLoop Subscription Agreement]: http://strongloop.com/license
diff --git a/apidocs/.eslintrc b/apidocs/.eslintrc
new file mode 100644
index 0000000..04e9789
--- /dev/null
+++ b/apidocs/.eslintrc
@@ -0,0 +1,6 @@
+{
+ "extends": "../.eslintrc",
+ "rules": {
+ "quotes": ["off"]
+ }
+}
\ No newline at end of file
diff --git a/apidocs/describe-builtin-models.js b/apidocs/describe-builtin-models.js
index accf462..1b17115 100644
--- a/apidocs/describe-builtin-models.js
+++ b/apidocs/describe-builtin-models.js
@@ -1,3 +1,9 @@
+// Copyright IBM Corp. 2014,2016. All Rights Reserved.
+// Node module: loopback-sdk-angular
+// This file is licensed under the MIT License.
+// License text available at https://opensource.org/licenses/MIT
+
+/* eslint quotes: ["error", "single"] */
var fs = require('fs');
var path = require('path');
@@ -6,7 +12,7 @@ var loopbackCoreJs = path.resolve(__dirname, 'loopback-core.js');
try {
var generator = require('..');
var loopback = require('loopback');
-} catch(err) {
+} catch (err) {
if (err.code === 'MODULE_NOT_FOUND' && fs.existsSync(loopbackCoreJs)) {
console.log('Cannot load the generator, node_modules were not installed.');
console.log('Ignoring the error since the output file is already there.');
diff --git a/index.js b/index.js
index 11eb64d..4bd8ba2 100644
--- a/index.js
+++ b/index.js
@@ -1,2 +1,6 @@
+// Copyright IBM Corp. 2014,2015. All Rights Reserved.
+// Node module: loopback-sdk-angular
+// This file is licensed under the MIT License.
+// License text available at https://opensource.org/licenses/MIT
exports.services = require('./lib/services');
diff --git a/karma.conf.js b/karma.conf.js
index 96e7770..129f6bc 100644
--- a/karma.conf.js
+++ b/karma.conf.js
@@ -1,3 +1,8 @@
+// Copyright IBM Corp. 2014,2016. All Rights Reserved.
+// Node module: loopback-sdk-angular
+// This file is licensed under the MIT License.
+// License text available at https://opensource.org/licenses/MIT
+
// Karma configuration
// Generated on Fri Jan 17 2014 19:17:51 GMT+0100 (CET)
@@ -20,7 +25,7 @@ module.exports = function(config) {
{ pattern: 'test.e2e/**/*.js', included: false },
// Include lib/ files to let Karma watch for changes there
- { pattern: 'lib/**/*.js', included: false }
+ { pattern: 'lib/**/*.js', included: false },
],
// list of files to exclude
@@ -35,7 +40,7 @@ module.exports = function(config) {
// CI friendly test output
junitReporter: {
- outputFile: 'karma-xunit.xml'
+ outputFile: 'karma-xunit.xml',
},
@@ -73,6 +78,6 @@ module.exports = function(config) {
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
- singleRun: false
+ singleRun: false,
});
};
diff --git a/lib/services.js b/lib/services.js
index 1b71d39..2c36624 100644
--- a/lib/services.js
+++ b/lib/services.js
@@ -1,8 +1,14 @@
+// Copyright IBM Corp. 2014,2016. All Rights Reserved.
+// Node module: loopback-sdk-angular
+// This file is licensed under the MIT License.
+// License text available at https://opensource.org/licenses/MIT
+
var fs = require('fs');
var ejs = require('ejs');
+var extend = require('util')._extend;
ejs.filters.q = function(obj) {
- return JSON.stringify(obj, null, 2 );
+ return JSON.stringify(obj, null, 2);
};
/**
@@ -12,23 +18,45 @@ ejs.filters.q = function(obj) {
* var generateServices = require('loopback-sdk-angular').services;
* var app = require('./server/server');
*
- * var client = generateServices(app, 'lbServices', '/api');
+ * var client = generateServices(app, {
+ * ngModuleName: 'lbServices',
+ * apiUrl: '/api'
+ * });
* require('fs').writeFileSync('client/loopback.js', client, 'utf-8');
* ```
*
+ * To preserve backwards compatibility, the three-arg variant is still
+ * supported:
+ *
+ * ```js
+ * var client = generateServices(app, 'lbServices', '/api');
+ * ```
+ *
* @param {Object} app The loopback application created via `app = loopback()`.
+ * @options {Object} options
* @param {string=} ngModuleName A name for the generated Angular module.
* Default: `lbServices`.
* @param {string=} apiUrl The URL where the client can access the LoopBack
* server app. Default: `/`.
+ * @param {Boolean} includeSchema Include model definition.
* @returns {string} The generated javascript code.
* @header generateServices
*/
-module.exports = function generateServices(app, ngModuleName, apiUrl) {
- ngModuleName = ngModuleName || 'lbServices';
- apiUrl = apiUrl || '/';
+module.exports = function generateServices(app, options) {
+ if (typeof options === 'string') {
+ // legacy API: generateServices(app, ngModuleName, apiUrl)
+ options = {
+ ngModuleName: arguments[1],
+ apiUrl: arguments[2],
+ };
+ }
- var models = describeModels(app);
+ options = extend({
+ ngModuleName: 'lbServices',
+ apiUrl: '/',
+ }, options);
+
+ var models = describeModels(app, options);
var servicesTemplate = fs.readFileSync(
require.resolve('./services.template.ejs'),
@@ -36,13 +64,13 @@ module.exports = function generateServices(app, ngModuleName, apiUrl) {
);
return ejs.render(servicesTemplate, {
- moduleName: ngModuleName,
+ moduleName: options.ngModuleName,
models: models,
- urlBase: apiUrl.replace(/\/+$/, '')
+ urlBase: options.apiUrl.replace(/\/+$/, ''),
});
};
-function describeModels(app) {
+function describeModels(app, options) {
var result = {};
app.handler('rest').adapter.getClasses().forEach(function(c) {
var name = c.name;
@@ -60,25 +88,25 @@ function describeModels(app) {
// the sharedCtor parameters should be added to the parameters
// of prototype methods.
c.methods.forEach(function fixArgsOfPrototypeMethods(method, key) {
- if (method.name=='create') {
+ if (method.name == 'create') {
var createMany = Object.create(method);
- createMany.name = 'createMany';
- createMany.isReturningArray = function() { return true; };
- c.methods.splice(key+1, 0, createMany);
+ createMany.name = 'createMany';
+ createMany.isReturningArray = function() { return true; };
+ c.methods.splice(key + 1, 0, createMany);
}
var ctor = method.restClass.ctor;
if (!ctor || method.sharedMethod.isStatic) return;
method.accepts = ctor.accepts.concat(method.accepts);
- if(!method.accepts) return;
+ if (!method.accepts) return;
// Any extra http action arguments in the path need to be added to the
// angular resource actions as params
method.accepts.forEach(function findResourceParams(arg) {
- if(!arg.http) return;
+ if (!arg.http) return;
- if(arg.http.source === 'path' && arg.arg !== 'id') {
- if(!method.resourceParams) {
+ if (arg.http.source === 'path' && arg.arg !== 'id') {
+ if (!method.resourceParams) {
method.resourceParams = [];
method.hasResourceParams = true;
}
@@ -94,6 +122,10 @@ function describeModels(app) {
buildScopes(result);
+ if (options.includeSchema) {
+ buildSchemas(result, app);
+ }
+
return result;
}
@@ -152,7 +184,7 @@ function buildScopeMethod(models, modelName, method) {
modelClass.scopes[scopeName] = {
methods: {},
- targetClass: targetClass
+ targetClass: targetClass,
};
} else if (modelClass.scopes[scopeName] === null) {
// Skip the scope, the warning was already reported
@@ -184,18 +216,18 @@ function buildScopeMethod(models, modelName, method) {
var reverseModel = findModelByName(models, targetClass);
reverseModel.methods.push(reverseMethod);
- if(reverseMethod.name.match(/create/)){
+ if (reverseMethod.name.match(/create/)) {
var createMany = Object.create(reverseMethod);
- createMany.name = createMany.name.replace(
+ createMany.name = createMany.name.replace(
/create/,
'createMany'
);
- createMany.internal = createMany.internal.replace(
+ createMany.internal = createMany.internal.replace(
/create/,
'createMany'
);
- createMany.isReturningArray = function() { return true; };
- reverseModel.methods.push(createMany);
+ createMany.isReturningArray = function() { return true; };
+ reverseModel.methods.push(createMany);
}
var scopeMethod = Object.create(method);
@@ -204,7 +236,7 @@ function buildScopeMethod(models, modelName, method) {
scopeMethod.deprecated = false;
scopeMethod.internal = false;
modelClass.scopes[scopeName].methods[apiName] = scopeMethod;
- if(scopeMethod.name.match(/create/)){
+ if (scopeMethod.name.match(/create/)) {
var scopeCreateMany = Object.create(scopeMethod);
scopeCreateMany.name = scopeCreateMany.name.replace(
/create/,
@@ -222,3 +254,25 @@ function findModelByName(models, name) {
return models[n];
}
}
+
+function buildSchemas(models, app) {
+ for (var modelName in models) {
+ var modelProperties = app.models[modelName].definition.properties;
+ var schema = {};
+ for (var prop in modelProperties) { // eslint-disable-line one-var
+ schema[prop] = extend({}, modelProperties[prop]);
+ // normalize types - convert from ctor (function) to name (string)
+ var type = schema[prop].type;
+ if (typeof type === 'function') {
+ type = type.modelName || type.name;
+ }
+ // TODO - handle array types
+ schema[prop].type = type;
+ }
+
+ models[modelName].modelSchema = {
+ name: modelName,
+ properties: schema,
+ };
+ }
+}
diff --git a/lib/services.template.ejs b/lib/services.template.ejs
index 2c9ac2b..9a0ca31 100644
--- a/lib/services.template.ejs
+++ b/lib/services.template.ejs
@@ -1,5 +1,6 @@
// CommonJS package manager support
-if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports === exports) {
+if (typeof module !== 'undefined' && typeof exports !== 'undefined' &&
+ module.exports === exports) {
// Export the *name* of this Angular module
// Sample usage:
//
@@ -9,17 +10,18 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex
module.exports = <%-: moduleName | q %>;
}
-(function(window, angular, undefined) {'use strict';
+(function(window, angular, undefined) {
+ 'use strict';
-var urlBase = <%-: urlBase | q %>;
-var authHeader = 'authorization';
+ var urlBase = <%-: urlBase | q %>;
+ var authHeader = 'authorization';
-function getHost(url) {
- var m = url.match(/^(?:https?:)?\/\/([^\/]+)/);
- return m ? m[1] : null;
-}
+ function getHost(url) {
+ var m = url.match(/^(?:https?:)?\/\/([^\/]+)/);
+ return m ? m[1] : null;
+ }
-var urlBaseHost = getHost(urlBase) || location.host;
+ var urlBaseHost = getHost(urlBase) || location.host;
/**
* @ngdoc overview
@@ -31,11 +33,10 @@ var urlBaseHost = getHost(urlBase) || location.host;
* the models exposed by the LoopBack server via the REST API.
*
*/
-var module = angular.module(<%-: moduleName | q %>, ['ngResource']);
+ var module = angular.module(<%-: moduleName | q %>, ['ngResource']);
<% for (var modelName in models) {
var meta = models[modelName];
-
// capitalize the model name
modelName = modelName[0].toUpperCase() + modelName.slice(1);
-%>
@@ -66,101 +67,109 @@ var module = angular.module(<%-: moduleName | q %>, ['ngResource']);
* including filter/where find query
*/ -%>
*/
-module.factory(
- <%-: modelName | q %>,
- ['LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) {
- var R = Resource(
- urlBase + <%-: meta.ctor.getFullPath() | q %>,
+ module.factory(
+ <%-: modelName | q %>,
+ [
+ 'LoopBackResource', 'LoopBackAuth', '$injector',
+ function(Resource, LoopBackAuth, $injector) {
+ var R = Resource(
+ urlBase + <%-: meta.ctor.getFullPath() | q %>,
<% /*
Constructor arguments are hardcoded for now.
We should generate it from sharedCtor.accepts instead.
*/ -%>
- { 'id': '@id' },
- {
+ { 'id': '@id' },
+ {
<% meta.methods.forEach(function(action) {
- var methodName = action.name.split('.').join('$');
--%>
-<% ngdocForMethod(modelName, methodName, action); -%>
- <%-: methodName | q %>: {
+ var methodName = action.name.split('.').join('$');
+ ngdocForMethod(modelName, methodName, action); -%>
+ <%-: methodName | q %>: {
<% if (action.isReturningArray()) { -%>
- isArray: true,
+ isArray: true,
<% } -%>
<% if (meta.isUser && methodName === 'login') { -%>
- params: {
- include: "user"
- },
- interceptor: {
- response: function(response) {
- var accessToken = response.data;
- LoopBackAuth.setUser(accessToken.id, accessToken.userId, accessToken.user);
- LoopBackAuth.rememberMe = response.config.params.rememberMe !== false;
- LoopBackAuth.save();
- return response.resource;
- }
- },
+ params: {
+ include: 'user',
+ },
+ interceptor: {
+ response: function(response) {
+ var accessToken = response.data;
+ LoopBackAuth.setUser(
+ accessToken.id, accessToken.userId, accessToken.user);
+ LoopBackAuth.rememberMe =
+ response.config.params.rememberMe !== false;
+ LoopBackAuth.save();
+ return response.resource;
+ },
+ },
<% } else if (meta.isUser && methodName === 'logout') { -%>
- interceptor: {
- response: function(response) {
- LoopBackAuth.clearUser();
- LoopBackAuth.clearStorage();
- return response.resource;
- }
- },
+ interceptor: {
+ response: function(response) {
+ LoopBackAuth.clearUser();
+ LoopBackAuth.clearStorage();
+ return response.resource;
+ },
+ responseError: function(responseError) {
+ LoopBackAuth.clearUser();
+ LoopBackAuth.clearStorage();
+ return responseError.resource;
+ },
+ },
<% } -%>
<% if (action.hasResourceParams) { -%>
- params: {
+ params: {
<% action.resourceParams.forEach(function(param, i, arr) { -%>
- '<%= param.arg %>': '@<%= param.arg %>'<%= i < arr.length -1 ? ',' : '' %>
+ '<%= param.arg %>': '@<%= param.arg %>',
<% }); //action.params.foreach -%>
- },
+ },
<% } -%>
- url: urlBase + <%-: action.getFullPath() | q %>,
- method: <%-: action.getHttpMethod() | q %>
- },
+ url: urlBase + <%-: action.getFullPath() | q %>,
+ method: <%-: action.getHttpMethod() | q %>,
+ },
<% }); // meta.methods.foreach -%>
<% if (meta.isUser) { -%>
- /**
- * @ngdoc method
- * @name <%- moduleName %>.<%- modelName %>#getCurrent
- * @methodOf <%- moduleName %>.<%- modelName %>
- *
- * @description
- *
- * Get data of the currently logged user. Fail with HTTP result 401
- * when there is no user logged in.
- *
- * @param {function(Object,Object)=} successCb
- * Success callback with two arguments: `value`, `responseHeaders`.
- *
- * @param {function(Object)=} errorCb Error callback with one argument:
- * `httpResponse`.
- *
- * @returns {Object} An empty reference that will be
- * populated with the actual data once the response is returned
- * from the server.
- */
- "getCurrent": {
- url: urlBase + <%-: meta.getPath() | q %> + "/:id",
- method: "GET",
- params: {
- id: function() {
- var id = LoopBackAuth.currentUserId;
- if (id == null) id = '__anonymous__';
- return id;
+ /**
+ * @ngdoc method
+ * @name <%- moduleName %>.<%- modelName %>#getCurrent
+ * @methodOf <%- moduleName %>.<%- modelName %>
+ *
+ * @description
+ *
+ * Get data of the currently logged user. Fail with HTTP result 401
+ * when there is no user logged in.
+ *
+ * @param {function(Object,Object)=} successCb
+ * Success callback with two arguments: `value`, `responseHeaders`.
+ *
+ * @param {function(Object)=} errorCb Error callback with one argument:
+ * `httpResponse`.
+ *
+ * @returns {Object} An empty reference that will be
+ * populated with the actual data once the response is returned
+ * from the server.
+ */
+ 'getCurrent': {
+ url: urlBase + <%-: meta.getPath() | q %> + '/:id',
+ method: 'GET',
+ params: {
+ id: function() {
+ var id = LoopBackAuth.currentUserId;
+ if (id == null) id = '__anonymous__';
+ return id;
+ },
+ },
+ interceptor: {
+ response: function(response) {
+ LoopBackAuth.currentUserData = response.data;
+ return response.resource;
+ },
+ },
+ __isGetCurrentUser__: true,
},
- },
- interceptor: {
- response: function(response) {
- LoopBackAuth.currentUserData = response.data;
- return response.resource;
- }
- },
- __isGetCurrentUser__ : true
- }
<% } -%>
- }
- );
+ }
+ );
<% meta.methods.forEach(function(action) {
@@ -218,15 +227,15 @@ module.factory(
};
<% } -%>
- /**
- * @ngdoc property
- * @name <%- moduleName %>.<%- modelName %>#modelName
- * @propertyOf <%- moduleName %>.<%- modelName %>
- * @description
- * The name of the model represented by this $resource,
- * i.e. `<%- modelName %>`.
- */
- R.modelName = <%-: modelName | q %>;
+ /**
+ * @ngdoc property
+ * @name <%- moduleName %>.<%- modelName %>#modelName
+ * @propertyOf <%- moduleName %>.<%- modelName %>
+ * @description
+ * The name of the model represented by this $resource,
+ * i.e. `<%- modelName %>`.
+ */
+ R.modelName = <%-: modelName | q %>;
<% for (var scopeName in meta.scopes) {
var scope = meta.scopes[scopeName];
@@ -276,12 +285,23 @@ module.factory(
<% }); // forEach methods name -%>
<% } // for each scope -%>
- return R;
- }]);
+<% if (meta.modelSchema) { -%>
+ /**
+ * @ngdoc object
+ * @name <%-: moduleName %>.<%- modelName %>#schema
+ * @propertyOf <%-: moduleName %>.<%- modelName %>
+ * @description
+ * The schema of the model represented by this $resource
+ */
+ R.schema = <%- JSON.stringify(meta.modelSchema, null, 2) -%>;
+<% } -%>
+
+ return R;
+ }]);
<% } // for modelName in models -%>
-module
+ module
.factory('LoopBackAuth', function() {
var props = ['accessTokenId', 'currentUserId', 'rememberMe'];
var propsPrefix = '$LoopBack$';
@@ -306,13 +326,13 @@ module
this.accessTokenId = accessTokenId;
this.currentUserId = userId;
this.currentUserData = userData;
- }
+ };
LoopBackAuth.prototype.clearUser = function() {
this.accessTokenId = null;
this.currentUserId = null;
this.currentUserData = null;
- }
+ };
LoopBackAuth.prototype.clearStorage = function() {
props.forEach(function(name) {
@@ -330,7 +350,7 @@ module
var key = propsPrefix + name;
if (value == null) value = '';
storage[key] = value;
- } catch(err) {
+ } catch (err) {
console.log('Cannot access local/session storage:', err);
}
}
@@ -343,11 +363,10 @@ module
.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('LoopBackAuthRequestInterceptor');
}])
- .factory('LoopBackAuthRequestInterceptor', [ '$q', 'LoopBackAuth',
+ .factory('LoopBackAuthRequestInterceptor', ['$q', 'LoopBackAuth',
function($q, LoopBackAuth) {
return {
'request': function(config) {
-
// filter out external requests
var host = getHost(config.url);
if (host && host !== urlBaseHost) {
@@ -360,16 +379,16 @@ module
// Return a stub 401 error for User.getCurrent() when
// there is no user logged in
var res = {
- body: { error: { status: 401 } },
+ body: { error: { status: 401 }},
status: 401,
config: config,
- headers: function() { return undefined; }
+ headers: function() { return undefined; },
};
return $q.reject(res);
}
return config || $q.when(config);
- }
- }
+ },
+ };
}])
/**
@@ -407,6 +426,17 @@ module
authHeader = header;
};
+ /**
+ * @ngdoc method
+ * @name <%-: moduleName %>.LoopBackResourceProvider#getAuthHeader
+ * @methodOf <%-: moduleName %>.LoopBackResourceProvider
+ * @description
+ * Get the header name that is used for sending the authentication token.
+ */
+ this.getAuthHeader = function() {
+ return authHeader;
+ };
+
/**
* @ngdoc method
* @name <%-: moduleName %>.LoopBackResourceProvider#setUrlBase
@@ -434,7 +464,7 @@ module
};
this.$get = ['$resource', function($resource) {
- return function(url, params, actions) {
+ var LoopBackResource = function(url, params, actions) {
var resource = $resource(url, params, actions);
// Angular always calls POST on $save()
@@ -448,6 +478,16 @@ module
};
return resource;
};
+
+ LoopBackResource.getUrlBase = function() {
+ return urlBase;
+ };
+
+ LoopBackResource.getAuthHeader = function() {
+ return authHeader;
+ };
+
+ return LoopBackResource;
}];
});
<%
@@ -464,28 +504,28 @@ function ngdocForMethod(modelName, methodName, action, responseModelName) {
<%
if (action.internal) {
-%>
- // INTERNAL. <%- action.internal %>
+ // INTERNAL. <%- action.internal %>
<%
return;
}
-%>
- /**
- * @ngdoc method
- * @name <%- moduleName %>.<%- modelName %>#<%- methodName %>
- * @methodOf <%- moduleName %>.<%- modelName %>
+ /**
+ * @ngdoc method
+ * @name <%- moduleName %>.<%- modelName %>#<%- methodName %>
+ * @methodOf <%- moduleName %>.<%- modelName %>
<% if (action.deprecated) { -%>
- * @deprecated <%- action.deprecated %>
+ * @deprecated <%- action.deprecated %>
<% } -%>
- *
- * @description
- *
+ *
+ * @description
+ *
<% if (!action.description) {
action.description = '\n' +
'(The remote method definition does not provide any description.)\n' +
'';
} -%>
- * <%-: action.description | replace:/\n/g, '\n * ' %>
- *
+ * <%-: action.description | replace:/\n/g, '\n * ' %>
+ *
<%
var params = action.accepts;
var postData;
@@ -498,77 +538,76 @@ if (action.getHttpMethod() == 'POST' || action.getHttpMethod() == 'PUT') {
});
}
-%>
- * @param {Object=} parameters Request parameters.
+ * @param {Object=} parameters Request parameters.
<% if (params.length == 0) { -%>
- *
- * This method does not accept any parameters.
- * Supply an empty object or omit this argument altogether.
+ *
+ * This method does not accept any parameters.
+ * Supply an empty object or omit this argument altogether.
<% } else { params.forEach(function(arg) { -%>
- *
- * - `<%- arg.arg %>` – `{<%- getJsDocType(arg) %>}` - <%-
-(arg.description || '').replace(/\n/g, '\n * ') %>
+ *
+ * - `<%- arg.arg %>` – `{<%- getJsDocType(arg) %>}` -<%-
+(arg.description ? ' ' + arg.description : '').replace(/\n/g, '\n * ') %>
<% if (meta.isUser && methodName === 'login' && arg.arg === 'include') { -%>
- * Default value: `user`.
+ * Default value: `user`.
<% } -%>
<% }); } -%>
<% if (meta.isUser && methodName === 'login') { -%>
- *
- * - `rememberMe` - `boolean` - Whether the authentication credentials
- * should be remembered in localStorage across app/browser restarts.
- * Default: `true`.
+ *
+ * - `rememberMe` - `boolean` - Whether the authentication credentials
+ * should be remembered in localStorage across app/browser restarts.
+ * Default: `true`.
<% } -%>
<% if (postData) { -%>
- *
- * @param {Object} postData Request data.
+ *
+ * @param {Object} postData Request data.
<% if (postData.length == 0) { -%>
- *
- * This method does not accept any data. Supply an empty object.
+ *
+ * This method does not accept any data. Supply an empty object.
<% } else if (postData.length == 1 && postData[0].http &&
postData[0].http.source == 'body') { -%>
- *
- * This method expects a subset of model properties as request parameters.
+ *
+ * This method expects a subset of model properties as request parameters.
<% } else {
postData.forEach(function(arg) { -%>
- *
- * - `<%- arg.arg %>` – `{<%- getJsDocType(arg) %>}` - <%-
-(arg.description || '').replace(/\n/g, '\n * ') %>
+ *
+ * - `<%- arg.arg %>` – `{<%- getJsDocType(arg) %>}` -<%-
+(arg.description ? ' ' + arg.description : '').replace(/\n/g, '\n * ') %>
<% });
}
} -%>
- *
+ *
<% var returnType = action.isReturningArray() ? 'Array.