From a4934b6021c80d6f7d53f5f7ed5723c30672b569 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 13:19:26 +0100 Subject: [PATCH 01/19] Extract DeletableMixin, improve mixin docs --- lib/resource/InstanceResource.js | 16 +++++----------- lib/resource/mixins/DeletableMixin.js | 22 ++++++++++++++++++++++ lib/resource/mixins/SaveableMixin.js | 21 ++++++++++++++------- 3 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 lib/resource/mixins/DeletableMixin.js diff --git a/lib/resource/InstanceResource.js b/lib/resource/InstanceResource.js index 673a16b6..2d2f3130 100644 --- a/lib/resource/InstanceResource.js +++ b/lib/resource/InstanceResource.js @@ -4,12 +4,16 @@ var async = require('async'); var Resource = require('./Resource'); var SaveableMixin = require('./mixins/SaveableMixin'); +var DeletableMixin = require('./mixins/DeletableMixin'); var utils = require('../utils'); /** * @class InstanceResource * * Low-level resource wrapper for Stormpath resource objects. + * + * @mixes SaveableMixin + * @mixes DeletableMixin */ function InstanceResource() { InstanceResource.super_.apply(this, arguments); @@ -17,6 +21,7 @@ function InstanceResource() { utils.inherits(InstanceResource, Resource); utils.applyMixin(InstanceResource, SaveableMixin); +utils.applyMixin(InstanceResource, DeletableMixin); /** * @private @@ -77,17 +82,6 @@ InstanceResource.prototype.get = function getResource() { this.dataStore.getResource(val.href, query, ctor, callback); }; -/** - * Deletes this resource from the API. - * - * @param {Function} callback - * The function to call when the delete operation is complete. Will be called - * with the parameter (err). - */ -InstanceResource.prototype.delete = function deleteResource(callback) { - this.dataStore.deleteResource(this, callback); -}; - /** * Removes this resource, and all of it's linked resources, e.g. Custom Data, from the local cache. * diff --git a/lib/resource/mixins/DeletableMixin.js b/lib/resource/mixins/DeletableMixin.js new file mode 100644 index 00000000..9a3ded80 --- /dev/null +++ b/lib/resource/mixins/DeletableMixin.js @@ -0,0 +1,22 @@ +function deleteResource(callback) { + this.dataStore.deleteResource(this, callback); +} + +/** +* Provides methods used for deleting resources. It is not meant to be used +* directly, and should instead be applied to resource classes. +* +* @mixin +*/ +var DeletableMixin = { + /** + * Deletes a resource from the API. + * + * @param {Function} callback + * The function to call when the delete operation is complete. Will be called + * with the parameter (err). + */ + delete: deleteResource +}; + +module.exports = DeletableMixin; diff --git a/lib/resource/mixins/SaveableMixin.js b/lib/resource/mixins/SaveableMixin.js index 36eacee9..7b992099 100644 --- a/lib/resource/mixins/SaveableMixin.js +++ b/lib/resource/mixins/SaveableMixin.js @@ -14,13 +14,7 @@ function applyCustomDataUpdatesIfNecessary(cb){ return cb(); } -/** - * Save changes to this resource. - * - * @param {Function} callback - * The function to call when the save operation is complete. Will be called - * with the parameters (err, updatedResource). - */ + function saveResource(callback) { var self = this; self._applyCustomDataUpdatesIfNecessary(function () { @@ -28,8 +22,21 @@ function saveResource(callback) { }); } +/** +* Provides methods used for saving resources. It is not meant to be used +* directly, and should instead be applied to resource classes. +* +* @mixin +*/ var SaveableMixin = { _applyCustomDataUpdatesIfNecessary: applyCustomDataUpdatesIfNecessary, + /** + * Save changes to this resource. + * + * @param {Function} callback + * The function to call when the save operation is complete. Will be called + * with the parameters (err, updatedResource). + */ save: saveResource }; From f7bd5604b62644b6dee7bead84f07de5d1b6d649 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 13:19:42 +0100 Subject: [PATCH 02/19] Update AccessToken with methods, mixin and docs --- lib/resource/AccessToken.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/resource/AccessToken.js b/lib/resource/AccessToken.js index 1b7d421b..1a5172bb 100644 --- a/lib/resource/AccessToken.js +++ b/lib/resource/AccessToken.js @@ -1,10 +1,14 @@ 'use strict'; var utils = require('../utils'); +var DeletableMixin = require('./mixins/DeletableMixin'); /** * @class AccessToken * + * @augments Resource + * @mixes DeletableMixin + * * @description * * Encapsulates a Stormpath OAuth Access Token Resource. For full @@ -33,18 +37,22 @@ function AccessToken() { AccessToken.super_.apply(this, arguments); } -// TODO: implement getAccount(), getRefreshToken() - -utils.inherits(AccessToken, require('./InstanceResource')); +// TODO: implement getRefreshToken() -module.exports = AccessToken; +utils.inherits(AccessToken, require('./Resource')); +utils.applyMixin(AccessToken, DeletableMixin); /** - * Deletes this resource from the API. - * - * @method AccessToken.delete - * - * @param {Function} callback - * The function to call when the delete operation is complete. Will be called - * with the parameter (err). - */ +* Gets and returns the account associated with this access token. +* +* @param {ExpansionOptions=} opts Options for expanding the fetched Account +* +* @param {Function} callback The function to call after the operation is finished. +* It is called with (err, {@link Account}). +*/ +AccessToken.prototype.getAccount = function getAccount(/* [opts,] callback */) { + var args = utils.resolveArgs(arguments, ['options', 'callback'], true); + return this.dataStore.getResource(this.account.href, args.options, require('./Account'), args.callback); +}; + +module.exports = AccessToken; From 5f912b3ff4aec790b96acaece0eea66c415bdc08 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 13:20:03 +0100 Subject: [PATCH 03/19] Add new getter to Account docs --- lib/resource/Account.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/resource/Account.js b/lib/resource/Account.js index 563890c3..0fe5d5d4 100644 --- a/lib/resource/Account.js +++ b/lib/resource/Account.js @@ -30,6 +30,7 @@ var utils = require('../utils'); * - {@link Organization#getAccounts Organization.getAccounts()} * - {@link Phone#getAccount Phone.getAccount()} * - {@link Factor#getAccount Factor.getAccount()} + * - {@link AccessToken#getAccount AccessToken.getAccount()} * * @augments {DirectoryChildResource} * From f765de0bacb94a5e341e813feb57a68c63e358c0 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 13:30:44 +0100 Subject: [PATCH 04/19] Add unit tests for AccessToken --- test/sp.resource.accessToken_test.js | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/sp.resource.accessToken_test.js diff --git a/test/sp.resource.accessToken_test.js b/test/sp.resource.accessToken_test.js new file mode 100644 index 00000000..3704c028 --- /dev/null +++ b/test/sp.resource.accessToken_test.js @@ -0,0 +1,83 @@ +/* jshint -W030 */ +var common = require('./common'); +var sinon = common.sinon; +var assert = common.assert; +var DataStore = require('../lib/ds/DataStore'); +var AccessToken = require('../lib/resource/AccessToken'); +var Account = require('../lib/resource/Account'); + +describe('Resources: ', function() { + var dataStore; + + before(function() { + dataStore = new DataStore({ + client: { + apiKey: { + id: 1, + secret: '6b2c3912-4779-49c1-81e7-23c204f43d2d' + } + } + }); + }); + + describe('AccessToken resource', function() { + describe('structure and inheritance', function() { + it('should inherit from Resource', function() { + assert.ok(AccessToken.super_); + assert.equal(AccessToken.super_.name, 'Resource'); + }); + + it('should have a defined delete method', function() { + var accessToken = new AccessToken({}, dataStore); + + assert.ok(accessToken.delete); + assert.isFunction(accessToken.delete); + }); + }); + + describe('.getAccount()', function() { + var sandbox; + var getResourceStub; + var cbSpy; + var opts; + var data; + var accessToken; + + before(function() { + sandbox = sinon.sandbox.create(); + getResourceStub = sinon.stub(dataStore, 'getResource', function(href, opts, ctor, cb) { + return cb(); + }); + + cbSpy = sinon.spy(); + + opts = {q: 'boomExpand!'}; + + data = { + account: { + href: 'boom!' + } + }; + + accessToken = new AccessToken(data, dataStore); + + accessToken.getAccount(cbSpy); + accessToken.getAccount(opts, cbSpy); + }); + + after(function() { + sandbox.restore(); + }); + + it('should get the account', function() { + /* jshint -W030 */ + getResourceStub.should.have.been.calledTwice; + cbSpy.should.have.been.calledTwice; + /* jshint +W030 */ + + getResourceStub.should.have.been.calledWith('boom!', null, Account, cbSpy); + getResourceStub.should.have.been.calledWith('boom!', opts, Account, cbSpy); + }); + }); + }); +}); From 0b4e6cb00d9468422d60c5aadea57b2db4d06bad Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 13:41:21 +0100 Subject: [PATCH 05/19] Update the AccountCreationPolicy resource, inheritance and docs --- lib/resource/AccountCreationPolicy.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/resource/AccountCreationPolicy.js b/lib/resource/AccountCreationPolicy.js index 69fd2ca3..b32a940c 100644 --- a/lib/resource/AccountCreationPolicy.js +++ b/lib/resource/AccountCreationPolicy.js @@ -1,9 +1,13 @@ -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); +var SaveableMixin = require('./mixins/SaveableMixin'); var utils = require('../utils'); /** * @class AccountCreationPolicy * + * @augments Resource + * @mixes SaveableMixin + * * @description * Encapsulates the account creation policy of a {@link Directory}. For full documentation of the this resource, please see * [REST API Reference: Account Creation Policy](https://docs.stormpath.com/rest/product-guide/latest/reference.html#account-creation-policy). @@ -19,23 +23,11 @@ var utils = require('../utils'); * The JSON representation of this resource, retrieved the Stormpath REST API. */ -/** - * @method AccountCreationPolicy.save - * - * @description - * - * Save changes to this resource. - * - * @param {Function} callback - * The function to call when the save operation is complete. Will be called - * with the parameters (err, updatedResource). - */ - - function AccountCreationPolicy() { AccountCreationPolicy.super_.apply(this, arguments); } -utils.inherits(AccountCreationPolicy, InstanceResource); +utils.inherits(AccountCreationPolicy, Resource); +utils.applyMixin(AccountCreationPolicy, SaveableMixin); -module.exports = AccountCreationPolicy; \ No newline at end of file +module.exports = AccountCreationPolicy; From bc6ea5b6bf2c47dc941084e135eeccbc2fb3ec7b Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 14:14:57 +0100 Subject: [PATCH 06/19] Update DataStore specification to only require a Resource --- lib/ds/DataStore.js | 9 +++++---- test/sp.ds.datastore_test.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ds/DataStore.js b/lib/ds/DataStore.js index 3db5e8dd..751ce993 100644 --- a/lib/ds/DataStore.js +++ b/lib/ds/DataStore.js @@ -6,6 +6,7 @@ var _ = require('underscore'); var ApiKey = require('../resource/ApiKey'); var ApiKeyEncryptedOptions = require('../authc/ApiKeyEncryptedOptions'); var CacheHandler = require('../cache/CacheHandler'); +var Resource = require('../resource/Resource'); var InstanceResource = require('../resource/InstanceResource'); var NonceStore = require('./NonceStore'); var RequestExecutor = require('./RequestExecutor'); @@ -105,7 +106,7 @@ DataStore.prototype._wrapGetResourceResponse = * @param {Object} query [optional=undefined] * Key/value pairs to use as query parameters to `href`. * - * @param {Function} instanceCtor [optional=InstanceResource] + * @param {Function} instanceCtor [optional=Resource] * The Constructor function to invoke for any Instance Resource returned by the server. * If the resource returned by the server is a single resource, this function is used to * construct the resource. If the resource returned by the server is a collection, @@ -342,7 +343,7 @@ DataStore.prototype.exec = function executeRequest(callback){ * @param {Object} data * The resource (name/value pairs) to send to the server. * - * @param {Function} instanceCtor [optional=InstanceResource] + * @param {Function} instanceCtor [optional=Resource] * The Constructor function to invoke for any Instance Resource returned by the server. * If the resource returned by the server is a single resource, this function is used to * construct the resource. If the resource returned by the server is a collection, @@ -365,8 +366,8 @@ DataStore.prototype.createResource = function createResource(/* parentHref, [que var query = (args.length > 0) ? args.pop() : null; callback = callback || noop; - if (!utils.isAssignableFrom(InstanceResource, ctor)) { - throw new Error("If specifying a constructor function, it must be for class equal to or a subclass of InstanceResource."); + if (!utils.isAssignableFrom(Resource, ctor)) { + throw new Error("If specifying a constructor function, it must be for class equal to or a subclass of Resource."); } var request = { uri: parentHref, method: 'POST' }; diff --git a/test/sp.ds.datastore_test.js b/test/sp.ds.datastore_test.js index b41fb63e..54a64393 100644 --- a/test/sp.ds.datastore_test.js +++ b/test/sp.ds.datastore_test.js @@ -346,7 +346,7 @@ describe('ds:', function () { it('should throw error', function () { callToCreateResourceWithInvalidResouceCtor - .should.throw(/constructor function.*InstanceResource/i); + .should.throw(/constructor function.*Resource/i); }); }); From 50975654d5fec00f25fb3b1407108d0e8882aa46 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 14:16:41 +0100 Subject: [PATCH 07/19] Update the AccountStoreMapping to avoid breaking changes --- lib/resource/AccountStoreMapping.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/resource/AccountStoreMapping.js b/lib/resource/AccountStoreMapping.js index fc68354f..59f3c7c8 100644 --- a/lib/resource/AccountStoreMapping.js +++ b/lib/resource/AccountStoreMapping.js @@ -6,6 +6,8 @@ var InstanceResource = require('./InstanceResource'); /** * @class AccountStoreMapping * + * @augments InstanceResource + * * @description * * Encapsulates an Account Store Mapping Resource, and is a base class for From d173fe3ca06af663f434e4806fdab2ed261eacb3 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 14:27:17 +0100 Subject: [PATCH 08/19] Update AuthenticationResult to use mere Resource --- lib/resource/AuthenticationResult.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/resource/AuthenticationResult.js b/lib/resource/AuthenticationResult.js index a2062b77..244f8104 100644 --- a/lib/resource/AuthenticationResult.js +++ b/lib/resource/AuthenticationResult.js @@ -2,7 +2,7 @@ var nJwt = require('njwt'); -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); var utils = require('../utils'); /** @@ -27,7 +27,7 @@ function AuthenticationResult() { Object.defineProperty(this, 'ttl', { enumerable:false, writable:true, value: 3600 }); } -utils.inherits(AuthenticationResult, InstanceResource); +utils.inherits(AuthenticationResult, Resource); /** * Retrieves the account resource of the user that has been authenticated. From af84197fed0d81590e0f3f7e2a80086b33d7c21c Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:21:04 +0100 Subject: [PATCH 09/19] Update the Challenge resource --- lib/resource/Challenge.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/resource/Challenge.js b/lib/resource/Challenge.js index 40c5593c..33568ab4 100644 --- a/lib/resource/Challenge.js +++ b/lib/resource/Challenge.js @@ -1,6 +1,7 @@ 'use strict'; -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); +var SaveableMixin = require('./mixins/SaveableMixin'); var FactorCtor = require('./FactorInstantiator').Constructor; var utils = require('../utils'); @@ -20,7 +21,7 @@ var utils = require('../utils'); * - {@link SmsFactor#createChallenge SmsFactor.createChallenge()} * - {@link GoogleAuthenticatorFactor#createChallenge GoogleAuthenticatorFactor.createChallenge()} * - * @augments {InstanceResource} + * @augments {Resource} * * @param {Object} challengeResource * @@ -30,7 +31,8 @@ function Challenge() { Challenge.super_.apply(this, arguments); } -utils.inherits(Challenge, InstanceResource); +utils.inherits(Challenge, Resource); +utils.applyMixin(Challenge, SaveableMixin); /** * Retrieves the factor instance ({@link SmsFactor} or {@link GoogleAuthenticatorFactor}) From 2011a370d41d7b25641460d2c94b919a9c1a8705 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:21:16 +0100 Subject: [PATCH 10/19] Update Custom Data --- lib/resource/CustomData.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/resource/CustomData.js b/lib/resource/CustomData.js index 90fb38e0..f5779caa 100644 --- a/lib/resource/CustomData.js +++ b/lib/resource/CustomData.js @@ -115,6 +115,8 @@ CustomData.prototype.remove = function removeCustomDataField(fieldName){ /** * Save changes to this custom data resource. * + * @override + * * @param {Function} callback * The function to call when the save operation is complete. Will be called * with the parameters (err, updatedCustomDataResource). From a020fd3b1165ad13307aa27a7c92079d5b392290 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:44:22 +0100 Subject: [PATCH 11/19] Update FactorInstantiator --- lib/resource/FactorInstantiator.js | 8 ++++---- test/sp.resource.factorInstantiator_test.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/resource/FactorInstantiator.js b/lib/resource/FactorInstantiator.js index 9cd4f904..7da842a6 100644 --- a/lib/resource/FactorInstantiator.js +++ b/lib/resource/FactorInstantiator.js @@ -4,7 +4,7 @@ var utils = require('../utils'); var Factor = require('./Factor'); var SmsFactor = require('./SmsFactor'); var GoogleAuthenticatorFactor = require('./GoogleAuthenticatorFactor'); -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); /** * Retrieves the constructor for a correct {@link Factor} instance ({@link SmsFactor} or @@ -45,10 +45,10 @@ function getFactorConstructor(/* factor */) { * The constructor for {@link Factor} instances ({@link SmsFactor} or * {@link GoogleAuthenticatorFactor}). It parses the data to construct the * correct constructor, and calls it with the data. It is used for polymorphic -* factor instantiation. It augments {@link InstanceResource} to adhere to the +* factor instantiation. It augments {@link Resource} to adhere to the * interface used for instantiation in {@link ResourceFactory}. * -* @augments InstanceResource +* @augments Resource */ function FactorInstantiator() { var Ctor = getFactorConstructor.apply(this, arguments); @@ -62,7 +62,7 @@ function FactorInstantiator() { return new (Ctor.bind.apply(Ctor, argsWithContext))(); } -utils.inherits(FactorInstantiator, InstanceResource); +utils.inherits(FactorInstantiator, Resource); module.exports = { Constructor: FactorInstantiator, diff --git a/test/sp.resource.factorInstantiator_test.js b/test/sp.resource.factorInstantiator_test.js index 9aa22888..90b52ca2 100644 --- a/test/sp.resource.factorInstantiator_test.js +++ b/test/sp.resource.factorInstantiator_test.js @@ -4,7 +4,7 @@ var common = require('./common'); var assert = common.assert; var sinon = common.sinon; -var InstanceResource = require('../lib/resource/InstanceResource'); +var Resource = require('../lib/resource/Resource'); var FactorInstantiator = require('../lib/resource/FactorInstantiator'); var FactorConstructor = FactorInstantiator.Constructor; var Factor = require('../lib/resource/Factor'); @@ -22,8 +22,8 @@ describe('FactorInstantiator#Constructor', function() { sandbox.restore(); }); - it('should inherit from InstanceResource', function() { - assert.equal(FactorConstructor.super_, InstanceResource); + it('should inherit from Resource', function() { + assert.equal(FactorConstructor.super_, Resource); }); it('should construct an SmsFactor if type is SMS', function() { From 1bbd34a0958c031527141fc185014f7e33edb8dd Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:44:30 +0100 Subject: [PATCH 12/19] Update field --- lib/resource/Field.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/resource/Field.js b/lib/resource/Field.js index d29cc3d2..c002443c 100644 --- a/lib/resource/Field.js +++ b/lib/resource/Field.js @@ -1,11 +1,15 @@ 'use strict'; var Resource = require('./Resource'); +var SaveableMixin = require('./mixins/SaveableMixin'); var utils = require('../utils'); /** * @class Field * + * @augments Resource + * @mixes SaveableMixin + * * @description * Encapsulates an account field, as part of a {@link Schema}. * @@ -18,16 +22,6 @@ function Field(){ } utils.inherits(Field, Resource); +utils.applyMixin(Field, SaveableMixin); -/** - * Save changes to this resource. - * - * @param {Function} callback - * The function to call when the save operation is complete. Will be called - * with the parameters (err, updatedResource). - */ -Field.prototype.save = function save(callback) { - this.dataStore.saveResource(this, callback); -}; - -module.exports = Field; \ No newline at end of file +module.exports = Field; From 63ee013432a3ad7b2edb8fc6ec19486dcbd4b72a Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:44:43 +0100 Subject: [PATCH 13/19] Update OAuthPolicy resource --- lib/resource/OAuthPolicy.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/resource/OAuthPolicy.js b/lib/resource/OAuthPolicy.js index 3e968681..a4a92b4b 100644 --- a/lib/resource/OAuthPolicy.js +++ b/lib/resource/OAuthPolicy.js @@ -1,11 +1,15 @@ 'use strict'; var utils = require('../utils'); -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); +var SaveableMixin = require('./mixins/SaveableMixin'); /** * @class OAuthPolicy * + * @augments Resource + * @mixes SaveableMixin + * * @description * * Encapsulates a OAuth Policy resource of an {@link Application}. For full @@ -29,19 +33,7 @@ function OAuthPolicy() { OAuthPolicy.super_.apply(this, arguments); } -utils.inherits(OAuthPolicy, InstanceResource); +utils.inherits(OAuthPolicy, Resource); +utils.applyMixin(OAuthPolicy, SaveableMixin); module.exports = OAuthPolicy; - - -/** - * @method OAuthPolicy.save - * - * @description - * - * Save changes to this resource. - * - * @param {Function} callback - * The function to call when the save operation is complete. Will be called - * with the parameters (err, updatedResource). - */ \ No newline at end of file From d78255a855dc23a02c87cb4c744232e2635ee1c2 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:44:58 +0100 Subject: [PATCH 14/19] Update PasswordResetToken resource --- lib/resource/PasswordResetToken.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/resource/PasswordResetToken.js b/lib/resource/PasswordResetToken.js index f5625d55..01c9682e 100644 --- a/lib/resource/PasswordResetToken.js +++ b/lib/resource/PasswordResetToken.js @@ -1,6 +1,7 @@ 'use strict'; -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); +var SaveableMixin = require('./mixins/SaveableMixin'); var utils = require('../utils'); /** @@ -27,7 +28,9 @@ var utils = require('../utils'); function PasswordResetToken() { PasswordResetToken.super_.apply(this, arguments); } -utils.inherits(PasswordResetToken, InstanceResource); + +utils.inherits(PasswordResetToken, Resource); +utils.applyMixin(PasswordResetToken, SaveableMixin); module.exports = PasswordResetToken; From 7674c4e9a9e445c646a64f5b25913ca45d5bcdaa Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:45:15 +0100 Subject: [PATCH 15/19] Update ProviderData resource --- lib/resource/ProviderData.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/resource/ProviderData.js b/lib/resource/ProviderData.js index c06ef5e5..7255bd03 100644 --- a/lib/resource/ProviderData.js +++ b/lib/resource/ProviderData.js @@ -1,6 +1,7 @@ 'use strict'; -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); +var SaveableMixin = require('./mixins/SaveableMixin'); var utils = require('../utils'); /** @@ -13,7 +14,7 @@ var utils = require('../utils'); * This class should not be manually constructed. It should be obtained from one of these methods: * - {@link Account#getProviderData Account.getProviderData()}. * - * @augments {InstanceResource} + * @augments {Resource} * * @param {Object} providerDataResource * The JSON representation of this resource, retrieved the Stormpath REST API. @@ -22,6 +23,7 @@ function ProviderData() { ProviderData.super_.apply(this, arguments); } -utils.inherits(ProviderData, InstanceResource); +utils.inherits(ProviderData, Resource); +utils.applyMixin(ProviderData, SaveableMixin); module.exports = ProviderData; From af5039dd424e702fe76e96d7bfc8291b620ab466 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 15:45:59 +0100 Subject: [PATCH 16/19] Update RefreshToken resource --- lib/resource/RefreshToken.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/resource/RefreshToken.js b/lib/resource/RefreshToken.js index 64ddb9b0..4e32b298 100644 --- a/lib/resource/RefreshToken.js +++ b/lib/resource/RefreshToken.js @@ -1,10 +1,14 @@ 'use strict'; var utils = require('../utils'); +var DeletableMixin = require('./mixins/DeletableMixin'); /** * @class RefreshToken * + * @augments Resource + * @mixes DeletableMixin + * * @description * * Encapsulates a Stormpath OAuth Refresh Token Resource. For full documentation @@ -30,7 +34,8 @@ function RefreshToken() { RefreshToken.super_.apply(this, arguments); } -utils.inherits(RefreshToken, require('./InstanceResource')); +utils.inherits(RefreshToken, require('./Resource')); +utils.applyMixin(RefreshToken, DeletableMixin); module.exports = RefreshToken; @@ -43,4 +48,3 @@ module.exports = RefreshToken; * The function to call when the delete operation is complete. Will be called * with the parameter (err). */ - From 204ee8956164089bf001d639a6f2448d718fa53b Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 17:25:58 +0100 Subject: [PATCH 17/19] Document basic Resource --- lib/resource/Resource.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/resource/Resource.js b/lib/resource/Resource.js index 55354b7c..93952f96 100644 --- a/lib/resource/Resource.js +++ b/lib/resource/Resource.js @@ -2,6 +2,20 @@ var utils = require('../utils'); +/** +* @class +* +* @description +* A bare-bones base representation of a resource in the Node Stormpath SDK. +* All resource instances must be based on this class (or a class that augments +* it). +* +* @param {Object=} data +* JavaScript object representing the resource's raw data +* +* @param {DataStore} dataStore +* The application's {@link DataStore} +*/ function Resource(data, dataStore) { // require moved here intentionally because of // issue related to @@ -33,4 +47,4 @@ function Resource(data, dataStore) { } utils.inherits(Resource, Object); -module.exports = Resource; \ No newline at end of file +module.exports = Resource; From 48089d9a0e165431318e6f6f90dd0cfaed46b909 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 17:26:27 +0100 Subject: [PATCH 18/19] Default to Resource instead of InstanceResource in factory --- lib/resource/ResourceFactory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/resource/ResourceFactory.js b/lib/resource/ResourceFactory.js index b0499b80..8209c57f 100644 --- a/lib/resource/ResourceFactory.js +++ b/lib/resource/ResourceFactory.js @@ -3,7 +3,7 @@ /* jshint -W003 */ var CollectionResource = require('./CollectionResource'); var CustomData = require('./CustomData'); -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); var utils = require('../utils'); var fs = require('fs'); @@ -78,7 +78,7 @@ function expandResource(expandedFields, resource, query, dataStore) { * @returns a new Resource memory instance */ function instantiate(InstanceConstructor, data, query, dataStore) { - var Ctor = utils.valueOf(InstanceConstructor, InstanceResource); + var Ctor = utils.valueOf(InstanceConstructor, Resource); if (utils.isAssignableFrom(CollectionResource, Ctor)) { throw new Error('InstanceConstructor argument cannot be a CollectionResource.'); From e90c4c8a1d79c24c72588f5f0d216165fe4bff83 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Mon, 14 Nov 2016 17:26:40 +0100 Subject: [PATCH 19/19] Update SAML mapping rules --- .../SamlAttributeStatementMappingRules.js | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/resource/SamlAttributeStatementMappingRules.js b/lib/resource/SamlAttributeStatementMappingRules.js index a4d0a98c..5f31b34e 100644 --- a/lib/resource/SamlAttributeStatementMappingRules.js +++ b/lib/resource/SamlAttributeStatementMappingRules.js @@ -1,11 +1,15 @@ 'use strict'; var utils = require('../utils'); -var InstanceResource = require('./InstanceResource'); +var Resource = require('./Resource'); +var SaveableMixin = require('./mixins/Saveable'); /** * @class SamlAttributeStatementMappingRules * + * @augments Resource + * @mixes SaveableMixin + * * @description * * Encapsulates a AttributeStatementMappingRules resource. @@ -32,18 +36,7 @@ function SamlAttributeStatementMappingRules() { SamlAttributeStatementMappingRules.super_.apply(this, arguments); } -utils.inherits(SamlAttributeStatementMappingRules, InstanceResource); +utils.inherits(SamlAttributeStatementMappingRules, Resource); +utils.applyMixin(SamlAttributeStatementMappingRules, SaveableMixin); module.exports = SamlAttributeStatementMappingRules; - -/** - * @method SamlAttributeStatementMappingRules.save - * - * @description - * - * Save changes to this resource. - * - * @param {Function} callback - * The function to call when the save operation is complete. Will be called - * with the parameters (err, updatedResource). - */ \ No newline at end of file