Skip to content

Commit

Permalink
Bumped version to 1.0.9 [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
fragsalat committed Jul 21, 2017
1 parent 8ed5d0b commit ada7e03
Show file tree
Hide file tree
Showing 40 changed files with 3,454 additions and 2,695 deletions.
76 changes: 74 additions & 2 deletions dist/amd/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define(['exports', 'react', 'react-dom', 'prop-types'], function (exports, _reac
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.render = exports.PropTypes = exports.PureComponent = exports.Component = exports.React = undefined;
exports.Component = exports.render = exports.PropTypes = exports.PureComponent = exports.React = undefined;

var _React_ = _interopRequireWildcard(_react);

Expand All @@ -29,11 +29,83 @@ define(['exports', 'react', 'react-dom', 'prop-types'], function (exports, _reac
}
}

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}

return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();

function _possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}

return call && (typeof call === "object" || typeof call === "function") ? call : self;
}

function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}

subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}

var React = exports.React = {
createElement: _React_.createElement || _React_.h
};
var Component = exports.Component = _React_.Component;
var PureComponent = exports.PureComponent = _React_.PureComponent || _React_.Component;
var PropTypes = exports.PropTypes = types;
var render = exports.render = ReactDOM.render;

var Component = exports.Component = function (_React_$Component) {
_inherits(Component, _React_$Component);

function Component() {
_classCallCheck(this, Component);

return _possibleConstructorReturn(this, (Component.__proto__ || Object.getPrototypeOf(Component)).apply(this, arguments));
}

_createClass(Component, [{
key: 'dispatchEvent',
value: function dispatchEvent(name, detail) {
var bubbles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;

var event = new CustomEvent(name, { detail: detail, bubbles: bubbles });

if (this.element) {
this.element.dispatchEvent(event);
}
}
}]);

return Component;
}(_React_.Component);
});
2 changes: 1 addition & 1 deletion dist/amd/ws-dropdown/ws-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ define(['exports', '../imports', './dropdown-menu', './dropdown-input'], functio
return item.label || item;
}).join(', ');
} else {
text = value.label || value;
text = value ? value.label : value;
}
}
return text;
Expand Down
213 changes: 213 additions & 0 deletions dist/amd/ws-header/authorization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
define(['exports'], function (exports) {
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;

try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);

if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}

return _arr;
}

return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}

return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();

var Authorization = exports.Authorization = function () {
function Authorization(storage) {
var loginUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var refreshUrl = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var clientId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
var businessPartnerId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';

_classCallCheck(this, Authorization);

this.storage = storage;
this.loginUrl = loginUrl;
this.refreshUrl = refreshUrl;
this.clientId = clientId;
this.businessPartnerId = businessPartnerId;

this.checkExpiration();
}

_createClass(Authorization, [{
key: 'onAccessTokenChange',
value: function onAccessTokenChange(callback) {
this.accessTokenChange = callback;
}
}, {
key: 'changeAccessToken',
value: function changeAccessToken(accessToken) {
if (typeof this.accessTokenChange === 'function') {
this.accessTokenChange(accessToken);
}
}
}, {
key: 'checkExpiration',
value: function checkExpiration() {
var _this = this;

var expiresAt = this.storage.get('expires_at') || 0;
var refreshToken = this.storage.get('refresh_token');
if (!refreshToken) {
return;
}

if (new Date().getTime() > expiresAt - 60000) {
this.refresh(refreshToken);
}

setTimeout(function () {
return _this.checkExpiration();
}, 59000);
}
}, {
key: 'tryFetchToken',
value: function tryFetchToken(queryString) {
var queryParams = {};
(queryString || '').split('&').forEach(function (keyValue) {
var _keyValue$split = keyValue.split('='),
_keyValue$split2 = _slicedToArray(_keyValue$split, 2),
key = _keyValue$split2[0],
value = _keyValue$split2[1];

queryParams[key] = decodeURIComponent(value);
});

if (queryParams.state) {
if (this.storage.get('state') !== queryParams.state) {
throw new Error('Unexpected authorisation response');
}
this.updateTokens(queryParams);
} else if (this.storage.get('access_token')) {
this.changeAccessToken(this.storage.get('access_token'));
} else {
this.changeAccessToken(null);
}
}
}, {
key: 'updateTokens',
value: function updateTokens(params) {
var expires = params.expires_in ? parseInt(params.expires_in, 10) : 3600;
this.storage.set('access_token', params.access_token);
this.storage.set('refresh_token', params.refresh_token);
this.storage.set('expires_at', new Date().getTime() + expires * 1000);

this.changeAccessToken(params.access_token);
}
}, {
key: 'authorize',
value: function authorize() {
var query = this.buildQuery([['business_partner_id', this.businessPartnerId], ['client_id', this.clientId], ['state', this.createAndRememberUUID()], ['response_type', 'token']]);

location.href = this.loginUrl + '?' + query;
}
}, {
key: 'refresh',
value: function refresh(token) {
var _this2 = this;

if (!this.refreshUrl || !token) {
return;
}
var data = this.buildQuery([['business_partner_id', this.businessPartnerId], ['client_id', this.clientId], ['grant_type', 'refresh_token'], ['refresh_token', token], ['state', this.createAndRememberUUID()], ['response_type', 'token']]);

var xhr = new XMLHttpRequest();
xhr.open('POST', this.refreshUrl, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.addEventListener('load', function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
_this2.updateTokens(JSON.parse(xhr.responseText));
} else {
throw new Error('Could not refresh token: ' + xhr.responseText);
}
}
});
xhr.send(data);
}
}, {
key: 'unauthorize',
value: function unauthorize() {
this.storage.remove('access_key');
this.storage.remove('refresh_key');
this.storage.remove('expires_at');
this.changeAccessToken(null);
}
}, {
key: 'createAndRememberUUID',
value: function createAndRememberUUID() {
var id = function id(length) {
return Math.round(Math.random() * Math.pow(10, length)).toString(16).substring(0, length);
};
var uuid = id(8) + '-' + id(4) + '-' + id(4) + '-' + id(4) + '-' + id(12);
this.storage.set('state', uuid);
return uuid;
}
}, {
key: 'buildQuery',
value: function buildQuery(params) {
return params.map(function (pair) {
return pair[0] + '=' + encodeURIComponent(pair[1]);
}).join('&');
}
}]);

return Authorization;
}();
});
58 changes: 58 additions & 0 deletions dist/amd/ws-header/storage/abstract-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
define(['exports'], function (exports) {
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}

return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();

var AbstractStorage = exports.AbstractStorage = function () {
function AbstractStorage(name) {
_classCallCheck(this, AbstractStorage);

this.name = name ? name + '-' : '';
}

_createClass(AbstractStorage, [{
key: 'set',
value: function set(key, value) {
throw new Error('\'' + this.constructor.name + '\' must implement function \'set\'');
}
}, {
key: 'get',
value: function get(key) {
throw new Error('\'' + this.constructor.name + '\' must implement function \'get\'');
}
}, {
key: 'remove',
value: function remove(key) {
throw new Error('\'' + this.constructor.name + '\' must implement function \'remove\'');
}
}]);

return AbstractStorage;
}();
});
Loading

0 comments on commit ada7e03

Please sign in to comment.