Skip to content

Commit

Permalink
Merge pull request #3 from Cox-Automotive/pr2
Browse files Browse the repository at this point in the history
Overhaul
  • Loading branch information
pofallon committed Feb 24, 2019
2 parents bb242d7 + 16e5c5d commit 54fc9df
Show file tree
Hide file tree
Showing 10 changed files with 9,926 additions and 8,862 deletions.
37 changes: 35 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"node": true,
"mocha": true
},
"plugins": [
"jsdoc"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"extends": "eslint:recommended",
Expand All @@ -23,6 +27,35 @@
"error",
"never"
],
"no-console": "off"
"no-console": "off",
"jsdoc/check-examples": 0,
"jsdoc/require-description": 0,
"jsdoc/require-description-complete-sentence": 0,
"jsdoc/require-returns-description": 0,
"jsdoc/check-param-names": 1,
"jsdoc/check-tag-names": 1,
"jsdoc/check-types": 1,
"jsdoc/newline-after-description": 1,
"jsdoc/no-undefined-types": 1,
"jsdoc/require-example": 1,
"jsdoc/require-hyphen-before-param-description": 1,
"jsdoc/require-param": 1,
"jsdoc/require-param-description": 1,
"jsdoc/require-param-name": 1,
"jsdoc/require-param-type": 1,
"jsdoc/require-returns": 1,
"jsdoc/require-returns-check": 1,
"jsdoc/require-returns-type": 1,
"jsdoc/valid-types": 1
},
"settings": {
"jsdoc": {
"tagNamePreference": {
"return": "returns",
"arg": "param",
"argument": "param",
"prop": "property"
}
}
}
}
}
415 changes: 324 additions & 91 deletions API.md

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions dist/alks.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
var alks = (function () {
'use strict';

var version = "1.0.1";

var fetch = window.fetch.bind(window);
var alks = function alks(props, existing) {
if ( existing === void 0 ) existing = {};
this.defaults = Object.assign({}, existing, { _fetch: fetch }, props);
};
alks.prototype._base64Encode = function _base64Encode (str) {
if ( str === void 0 ) str = '';
{
return btoa(str)
}
};
alks.prototype.create = function create (props) {
return(new alks(props, this.defaults))
};
Expand Down Expand Up @@ -67,22 +75,47 @@ var alks = (function () {
alks.prototype.deleteIAMUser = function deleteIAMUser (props) {
return(this._doFetch('IAMUser', props, 'DELETE').then(function () { return true; } ))
};
alks.prototype.version = function version (props) {
return this._doFetch('version', props, 'GET').then(function (results) { return pick(results, ['version']); })
};
alks.prototype.getLoginRole = function getLoginRole (props) {
var accountId = props.accountId;
var role = props.role;
return this._doFetch(("loginRoles/id/" + accountId + "/" + role), null).then(function (results) { return pick(results, ['account', 'role', 'iamKeyActive', 'maxKeyDuration']); })
};
alks.prototype.getAccessToken = function getAccessToken (props) {
return this._doFetch('accessToken', props).then(function (results) { return pick(results, ['accessToken', 'expiresIn']); }
)
};
alks.prototype.getRefreshTokens = function getRefreshTokens (props) {
return this._doFetch('refreshTokens', props, 'GET').then(function (results) { return results.refreshTokens.map(function (token) { return pick(token, ['clientId', 'id', 'userId', 'value']); }); }
)
};
alks.prototype.revoke = function revoke (props) {
return this._doFetch('revoke', props).then(function (results) { return results.statusMessage == 'Success'; }
)
};
alks.prototype._doFetch = function _doFetch (path, args, method) {
if ( args === void 0 ) args = { };
if ( method === void 0 ) method = 'POST';
var opts = Object.assign({}, this.defaults, args);
var headers = {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'User-Agent': ("AlksJS/" + (version)),
};
if (opts.accessToken) {
headers['Authorization'] = "Bearer " + (opts.accessToken);
delete opts.accessToken;
}
if (opts.userid || opts.password) {
console.error('The userid and password properties are deprecated and should be replaced with an access token');
var credentials = this._base64Encode(((opts.userid) + ":" + (opts.password)));
headers['Authorization'] = "Basic " + credentials;
delete opts.userid;
delete opts.password;
}
var responsePromise = opts._fetch(((opts.baseUrl) + "/" + path + "/"), {
method: method, headers: headers, body: JSON.stringify(opts)
method: method, headers: headers, body: method == 'GET' ? undefined : JSON.stringify(opts)
});
var jsonPromise = responsePromise.then(function (r) { return r.json(); }).catch(function () {});
return Promise.all([responsePromise, jsonPromise]).then(function (ref) {
Expand Down
2 changes: 1 addition & 1 deletion dist/alks.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 54fc9df

Please sign in to comment.