baasic-sdk-javascript
Version:
JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
105 lines (104 loc) • 4.68 kB
JavaScript
;
/* globals module */
/**
* @module registerClient
* @description Register Client provides an easy way to consume Application Registration REST API end-points. In order to obtain needed routes `registerClient` uses `registerRoute`.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var inversify_1 = require("inversify");
var httpApi_1 = require("../../httpApi");
var contracts_1 = require("../../core/contracts");
var _1 = require("./");
var RegisterClient = /** @class */ (function () {
function RegisterClient(registerRoute, apiClient, tokenHandler) {
this.registerRoute = registerRoute;
this.apiClient = apiClient;
this.tokenHandler = tokenHandler;
}
Object.defineProperty(RegisterClient.prototype, "routeDefinition", {
/**
* Provides direct access to `registerRoute`.
* @method
* @example registerClient.routeDefinition.get();
**/
get: function () {
return this.registerRoute;
},
enumerable: true,
configurable: true
});
/**
* Returns a promise that is resolved once the register create has been performed. This action will create a new user if completed successfully. Created user is not approved immediately, instead an activation e-mail is sent to the user.
* @param data A user account object that needs to be inserted into the system.
* @method
* @example registerClient.create({
activationUrl : '<activation-url>',
challengeIdentifier : '<challenge-identifier>',
challengeResponse : '<challenge-response>',
confirmPassword : '<confirm-password>',
email : '<email>',
password : '<password>',
username : '<username>'
})
.success(function (data) {
// perform success actions here
}).error(function (data, status) {
// perform error handling here
})
.finally (function () {});
**/
RegisterClient.prototype.create = function (data) {
return this.apiClient.post(this.routeDefinition.create(), this.routeDefinition.createParams(data));
};
/**
* Returns a promise that is resolved once the account activation action has been performed; this action activates a user account and success response returns the token resource.
* @param data Security code which uniquely identifies user account that needs to be activated.
* @returns A promise that is resolved once the account activation action has been performed.
* @method
* @example registerClient.activate({
activationToken : '<activation-token>'
})
.then(function (data) {
// perform success actions here
},
function (data, status) {
// perform error handling here
})
.finally (function () {});
**/
RegisterClient.prototype.activate = function (data) {
var self = this;
var promise = this.apiClient.put(this.registerRoute.activate(data), data);
promise.then(function (data) {
var token = {
token: data.data.access_token,
expires_in: data.data.expires_in,
sliding_window: data.data.sliding_window,
tokenUrl: data.data.access_url_token,
type: data.data.token_type
};
self.tokenHandler.store(token);
return data;
}, function (response) {
return response;
});
return promise;
};
RegisterClient = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__param(0, inversify_1.inject(_1.TYPES.RegisterRoute)),
tslib_1.__param(1, inversify_1.inject(httpApi_1.httpTYPES.ApiClient)),
tslib_1.__param(2, inversify_1.inject(contracts_1.TYPES.ITokenHandler)),
tslib_1.__metadata("design:paramtypes", [_1.RegisterRoute,
httpApi_1.ApiClient, Object])
], RegisterClient);
return RegisterClient;
}());
exports.RegisterClient = RegisterClient;
/**
* @overview
***Notes:**
- Refer to the [Baasic REST API](http://dev.baasic.com/api/reference/home) for detailed information about available Baasic REST API end-points.
- All end-point objects are transformed by the associated route definition.
*/