UNPKG

strong-arc

Version:

A visual suite for the StrongLoop API Platform

1,207 lines (1,140 loc) 43.5 kB
// CommonJS package manager support if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports === exports) { // Export the *name* of this Angular module // Sample usage: // // import lbServices from './lb-services'; // angular.module('app', [lbServices]); // module.exports = "BuildDeployAPI"; } (function(window, angular, undefined) { 'use strict'; var urlBase = "/build-deploy"; var authHeader = 'authorization'; function getHost(url) { var m = url.match(/^(?:https?:)?\/\/([^\/]+)/); return m ? m[1] : null; } var urlBaseHost = getHost(urlBase) || location.host; /** * @ngdoc overview * @name BuildDeployAPI * @module * @description * * The `BuildDeployAPI` module provides services for interacting with * the models exposed by the LoopBack server via the REST API. * */ var module = angular.module("BuildDeployAPI", ['ngResource']); /** * @ngdoc object * @name BuildDeployAPI.Build * @header BuildDeployAPI.Build * @object * * @description * * A $resource object for interacting with the `Build` model. * * ## Example * * See * {@link http://docs.angularjs.org/api/ngResource.$resource#example $resource} * for an example of using this object. * */ module.factory( "Build", [ 'LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) { var R = Resource( urlBase + "/Builds/:id", { 'id': '@id' }, { /** * @ngdoc method * @name BuildDeployAPI.Build#create * @methodOf BuildDeployAPI.Build * * @description * * Create a new instance of the model and persist it into the data source. * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "create": { url: urlBase + "/Builds", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Build#createMany * @methodOf BuildDeployAPI.Build * * @description * * Create a new instance of the model and persist it into the data source. * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @param {function(Array.<Object>,Object)=} successCb * Success callback with two arguments: `value`, `responseHeaders`. * * @param {function(Object)=} errorCb Error callback with one argument: * `httpResponse`. * * @returns {Array.<Object>} An empty reference that will be * populated with the actual data once the response is returned * from the server. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "createMany": { isArray: true, url: urlBase + "/Builds", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Build#upsert * @methodOf BuildDeployAPI.Build * * @description * * Patch an existing model instance or insert a new one into the data source. * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "upsert": { url: urlBase + "/Builds", method: "PUT", }, /** * @ngdoc method * @name BuildDeployAPI.Build#replaceOrCreate * @methodOf BuildDeployAPI.Build * * @description * * Replace an existing model instance or insert a new one into the data source. * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "replaceOrCreate": { url: urlBase + "/Builds/replaceOrCreate", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Build#upsertWithWhere * @methodOf BuildDeployAPI.Build * * @description * * Update an existing model instance or insert a new one into the data source based on the where criteria. * * @param {Object=} parameters Request parameters. * * - `where` – `{object=}` - Criteria to match model instances * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "upsertWithWhere": { url: urlBase + "/Builds/upsertWithWhere", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Build#exists * @methodOf BuildDeployAPI.Build * * @description * * Check whether a model instance exists in the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - Model id * * @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. * * Data properties: * * - `exists` – `{boolean=}` - */ "exists": { url: urlBase + "/Builds/:id/exists", method: "GET", }, /** * @ngdoc method * @name BuildDeployAPI.Build#findById * @methodOf BuildDeployAPI.Build * * @description * * Find a model instance by {{id}} from the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - Model id * * - `filter` – `{object=}` - Filter defining fields and include * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "findById": { url: urlBase + "/Builds/:id", method: "GET", }, /** * @ngdoc method * @name BuildDeployAPI.Build#replaceById * @methodOf BuildDeployAPI.Build * * @description * * Replace attributes for a model instance and persist it into the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - Model id * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "replaceById": { url: urlBase + "/Builds/:id/replace", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Build#find * @methodOf BuildDeployAPI.Build * * @description * * Find all instances of the model matched by filter from the data source. * * @param {Object=} parameters Request parameters. * * - `filter` – `{object=}` - Filter defining fields, where, include, order, offset, and limit * * @param {function(Array.<Object>,Object)=} successCb * Success callback with two arguments: `value`, `responseHeaders`. * * @param {function(Object)=} errorCb Error callback with one argument: * `httpResponse`. * * @returns {Array.<Object>} An empty reference that will be * populated with the actual data once the response is returned * from the server. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "find": { isArray: true, url: urlBase + "/Builds", method: "GET", }, /** * @ngdoc method * @name BuildDeployAPI.Build#findOne * @methodOf BuildDeployAPI.Build * * @description * * Find first instance of the model matched by filter from the data source. * * @param {Object=} parameters Request parameters. * * - `filter` – `{object=}` - Filter defining fields, where, include, order, offset, and limit * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "findOne": { url: urlBase + "/Builds/findOne", method: "GET", }, /** * @ngdoc method * @name BuildDeployAPI.Build#updateAll * @methodOf BuildDeployAPI.Build * * @description * * Update instances of the model matched by {{where}} from the data source. * * @param {Object=} parameters Request parameters. * * - `where` – `{object=}` - Criteria to match model instances * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * The number of instances updated */ "updateAll": { url: urlBase + "/Builds/update", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Build#deleteById * @methodOf BuildDeployAPI.Build * * @description * * Delete a model instance by {{id}} from the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - Model id * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "deleteById": { url: urlBase + "/Builds/:id", method: "DELETE", }, /** * @ngdoc method * @name BuildDeployAPI.Build#count * @methodOf BuildDeployAPI.Build * * @description * * Count instances of the model matched by where from the data source. * * @param {Object=} parameters Request parameters. * * - `where` – `{object=}` - Criteria to match model instances * * @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. * * Data properties: * * - `count` – `{number=}` - */ "count": { url: urlBase + "/Builds/count", method: "GET", }, /** * @ngdoc method * @name BuildDeployAPI.Build#prototype$updateAttributes * @methodOf BuildDeployAPI.Build * * @description * * Patch attributes for a model instance and persist it into the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - PersistedModel id * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "prototype$updateAttributes": { url: urlBase + "/Builds/:id", method: "PUT", }, /** * @ngdoc method * @name BuildDeployAPI.Build#createChangeStream * @methodOf BuildDeployAPI.Build * * @description * * Create a change stream. * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * - `options` – `{object=}` - * * @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. * * Data properties: * * - `changes` – `{ReadableStream=}` - */ "createChangeStream": { url: urlBase + "/Builds/change-stream", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Build#start * @methodOf BuildDeployAPI.Build * * @description * * <em> * (The remote method definition does not provide any description.) * </em> * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ "start": { url: urlBase + "/Builds/start", method: "POST", }, } ); /** * @ngdoc method * @name BuildDeployAPI.Build#patchOrCreate * @methodOf BuildDeployAPI.Build * * @description * * Patch an existing model instance or insert a new one into the data source. * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ R["patchOrCreate"] = R["upsert"]; /** * @ngdoc method * @name BuildDeployAPI.Build#updateOrCreate * @methodOf BuildDeployAPI.Build * * @description * * Patch an existing model instance or insert a new one into the data source. * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ R["updateOrCreate"] = R["upsert"]; /** * @ngdoc method * @name BuildDeployAPI.Build#patchOrCreateWithWhere * @methodOf BuildDeployAPI.Build * * @description * * Update an existing model instance or insert a new one into the data source based on the where criteria. * * @param {Object=} parameters Request parameters. * * - `where` – `{object=}` - Criteria to match model instances * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ R["patchOrCreateWithWhere"] = R["upsertWithWhere"]; /** * @ngdoc method * @name BuildDeployAPI.Build#update * @methodOf BuildDeployAPI.Build * * @description * * Update instances of the model matched by {{where}} from the data source. * * @param {Object=} parameters Request parameters. * * - `where` – `{object=}` - Criteria to match model instances * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * The number of instances updated */ R["update"] = R["updateAll"]; /** * @ngdoc method * @name BuildDeployAPI.Build#destroyById * @methodOf BuildDeployAPI.Build * * @description * * Delete a model instance by {{id}} from the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - Model id * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ R["destroyById"] = R["deleteById"]; /** * @ngdoc method * @name BuildDeployAPI.Build#removeById * @methodOf BuildDeployAPI.Build * * @description * * Delete a model instance by {{id}} from the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - Model id * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ R["removeById"] = R["deleteById"]; /** * @ngdoc method * @name BuildDeployAPI.Build#patchAttributes * @methodOf BuildDeployAPI.Build * * @description * * Patch attributes for a model instance and persist it into the data source. * * @param {Object=} parameters Request parameters. * * - `id` – `{*}` - PersistedModel id * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Build` object.) * </em> */ R["patchAttributes"] = R["prototype$updateAttributes"]; /** * @ngdoc property * @name BuildDeployAPI.Build#modelName * @propertyOf BuildDeployAPI.Build * @description * The name of the model represented by this $resource, * i.e. `Build`. */ R.modelName = "Build"; return R; }]); /** * @ngdoc object * @name BuildDeployAPI.Deployment * @header BuildDeployAPI.Deployment * @object * * @description * * A $resource object for interacting with the `Deployment` model. * * ## Example * * See * {@link http://docs.angularjs.org/api/ngResource.$resource#example $resource} * for an example of using this object. * */ module.factory( "Deployment", [ 'LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) { var R = Resource( urlBase + "/Deployments/:id", { 'id': '@id' }, { /** * @ngdoc method * @name BuildDeployAPI.Deployment#create * @methodOf BuildDeployAPI.Deployment * * @description * * <em> * (The remote method definition does not provide any description.) * </em> * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @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. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Deployment` object.) * </em> */ "create": { url: urlBase + "/Deployments", method: "POST", }, /** * @ngdoc method * @name BuildDeployAPI.Deployment#createMany * @methodOf BuildDeployAPI.Deployment * * @description * * <em> * (The remote method definition does not provide any description.) * </em> * * @param {Object=} parameters Request parameters. * * This method does not accept any parameters. * Supply an empty object or omit this argument altogether. * * @param {Object} postData Request data. * * This method expects a subset of model properties as request parameters. * * @param {function(Array.<Object>,Object)=} successCb * Success callback with two arguments: `value`, `responseHeaders`. * * @param {function(Object)=} errorCb Error callback with one argument: * `httpResponse`. * * @returns {Array.<Object>} An empty reference that will be * populated with the actual data once the response is returned * from the server. * * <em> * (The remote method definition does not provide any description. * This usually means the response is a `Deployment` object.) * </em> */ "createMany": { isArray: true, url: urlBase + "/Deployments", method: "POST", }, } ); /** * @ngdoc property * @name BuildDeployAPI.Deployment#modelName * @propertyOf BuildDeployAPI.Deployment * @description * The name of the model represented by this $resource, * i.e. `Deployment`. */ R.modelName = "Deployment"; return R; }]); module .factory('LoopBackAuth', function() { var props = ['accessTokenId', 'currentUserId', 'rememberMe']; var propsPrefix = '$LoopBack$'; function LoopBackAuth() { var self = this; props.forEach(function(name) { self[name] = load(name); }); this.currentUserData = null; } LoopBackAuth.prototype.save = function() { var self = this; var storage = this.rememberMe ? localStorage : sessionStorage; props.forEach(function(name) { save(storage, name, self[name]); }); }; LoopBackAuth.prototype.setUser = function(accessTokenId, userId, userData) { 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) { save(sessionStorage, name, null); save(localStorage, name, null); }); }; return new LoopBackAuth(); // Note: LocalStorage converts the value to string // We are using empty string as a marker for null/undefined values. function save(storage, name, value) { try { var key = propsPrefix + name; if (value == null) value = ''; storage[key] = value; } catch (err) { console.log('Cannot access local/session storage:', err); } } function load(name) { var key = propsPrefix + name; return localStorage[key] || sessionStorage[key] || null; } }) .config(['$httpProvider', function($httpProvider) { $httpProvider.interceptors.push('LoopBackAuthRequestInterceptor'); }]) .factory('LoopBackAuthRequestInterceptor', ['$q', 'LoopBackAuth', function($q, LoopBackAuth) { return { 'request': function(config) { // filter out external requests var host = getHost(config.url); if (host && host !== urlBaseHost) { return config; } if (LoopBackAuth.accessTokenId) { config.headers[authHeader] = LoopBackAuth.accessTokenId; } else if (config.__isGetCurrentUser__) { // Return a stub 401 error for User.getCurrent() when // there is no user logged in var res = { body: { error: { status: 401 }}, status: 401, config: config, headers: function() { return undefined; }, }; return $q.reject(res); } return config || $q.when(config); }, }; }]) /** * @ngdoc object * @name BuildDeployAPI.LoopBackResourceProvider * @header BuildDeployAPI.LoopBackResourceProvider * @description * Use `LoopBackResourceProvider` to change the global configuration * settings used by all models. Note that the provider is available * to Configuration Blocks only, see * {@link https://docs.angularjs.org/guide/module#module-loading-dependencies Module Loading & Dependencies} * for more details. * * ## Example * * ```js * angular.module('app') * .config(function(LoopBackResourceProvider) { * LoopBackResourceProvider.setAuthHeader('X-Access-Token'); * }); * ``` */ .provider('LoopBackResource', function LoopBackResourceProvider() { /** * @ngdoc method * @name BuildDeployAPI.LoopBackResourceProvider#setAuthHeader * @methodOf BuildDeployAPI.LoopBackResourceProvider * @param {string} header The header name to use, e.g. `X-Access-Token` * @description * Configure the REST transport to use a different header for sending * the authentication token. It is sent in the `Authorization` header * by default. */ this.setAuthHeader = function(header) { authHeader = header; }; /** * @ngdoc method * @name BuildDeployAPI.LoopBackResourceProvider#getAuthHeader * @methodOf BuildDeployAPI.LoopBackResourceProvider * @description * Get the header name that is used for sending the authentication token. */ this.getAuthHeader = function() { return authHeader; }; /** * @ngdoc method * @name BuildDeployAPI.LoopBackResourceProvider#setUrlBase * @methodOf BuildDeployAPI.LoopBackResourceProvider * @param {string} url The URL to use, e.g. `/api` or `//example.com/api`. * @description * Change the URL of the REST API server. By default, the URL provided * to the code generator (`lb-ng` or `grunt-loopback-sdk-angular`) is used. */ this.setUrlBase = function(url) { urlBase = url; urlBaseHost = getHost(urlBase) || location.host; }; /** * @ngdoc method * @name BuildDeployAPI.LoopBackResourceProvider#getUrlBase * @methodOf BuildDeployAPI.LoopBackResourceProvider * @description * Get the URL of the REST API server. The URL provided * to the code generator (`lb-ng` or `grunt-loopback-sdk-angular`) is used. */ this.getUrlBase = function() { return urlBase; }; this.$get = ['$resource', function($resource) { var LoopBackResource = function(url, params, actions) { var resource = $resource(url, params, actions); // Angular always calls POST on $save() // This hack is based on // http://kirkbushell.me/angular-js-using-ng-resource-in-a-more-restful-manner/ resource.prototype.$save = function(success, error) { // Fortunately, LoopBack provides a convenient `upsert` method // that exactly fits our needs. var result = resource.upsert.call(this, {}, this, success, error); return result.$promise || result; }; return resource; }; LoopBackResource.getUrlBase = function() { return urlBase; }; LoopBackResource.getAuthHeader = function() { return authHeader; }; return LoopBackResource; }]; }); })(window, window.angular);