diff --git a/dist/alks.cjs.js b/dist/alks.cjs.js index eb51e595..15e0c65d 100644 --- a/dist/alks.cjs.js +++ b/dist/alks.cjs.js @@ -719,7 +719,6 @@ class alks { * @param {Object} props - An object containing the following properties * @param {string} props.accountId - The 12-digit account ID associated with the custom role * @param {string} props.role - The user's role associated with the account - * @param {number} props.maxKeyDuration - The maximum key duration for this account * @returns {Promise} * @example * alks.getLoginRole({ @@ -730,8 +729,8 @@ class alks { */ getLoginRole(props) { const {accountId, role} = props; - return this._doFetch(`loginRoles/id/${accountId}/${role}`, null).then((results) => - pick(results, ['account', 'role', 'iamKeyActive', 'maxKeyDuration'])) + return this._doFetch(`loginRoles/id/${accountId}/${role}`, null, 'GET').then((results) => + pick(results.loginRole, ['account', 'role', 'iamKeyActive', 'maxKeyDuration'])) } /** diff --git a/dist/alks.esm.js b/dist/alks.esm.js index c3fa3a2c..df3fd43e 100644 --- a/dist/alks.esm.js +++ b/dist/alks.esm.js @@ -716,7 +716,6 @@ class alks { * @param {Object} props - An object containing the following properties * @param {string} props.accountId - The 12-digit account ID associated with the custom role * @param {string} props.role - The user's role associated with the account - * @param {number} props.maxKeyDuration - The maximum key duration for this account * @returns {Promise} * @example * alks.getLoginRole({ @@ -727,8 +726,8 @@ class alks { */ getLoginRole(props) { const {accountId, role} = props; - return this._doFetch(`loginRoles/id/${accountId}/${role}`, null).then((results) => - pick(results, ['account', 'role', 'iamKeyActive', 'maxKeyDuration'])) + return this._doFetch(`loginRoles/id/${accountId}/${role}`, null, 'GET').then((results) => + pick(results.loginRole, ['account', 'role', 'iamKeyActive', 'maxKeyDuration'])) } /** diff --git a/dist/alks.min.js b/dist/alks.min.js index 28564d2f..0225da0f 100644 --- a/dist/alks.min.js +++ b/dist/alks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).alks=t()}(this,function(){"use strict";var n=window.fetch.bind(window),t=function(e,t){void 0===t&&(t={}),this.defaults=Object.assign({},t,{_fetch:n},e)};t.prototype._base64Encode=function(e){return void 0===e&&(e=""),btoa(e)},t.prototype.create=function(e){return new t(e,this.defaults)},t.prototype.getAccounts=function(e){return this._doFetch("getAccounts",e).then(function(t){return Object.keys(t.accountListRole).map(function(e){return{account:e,role:t.accountListRole[e][0].role,iamKeyActive:t.accountListRole[e][0].iamKeyActive,maxKeyDuration:t.accountListRole[e][0].maxKeyDuration,skypieaAccount:t.accountListRole[e][0].skypieaAccount}})})},t.prototype.getKeys=function(e){return this._doFetch("getKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getIAMKeys=function(e){return this._doFetch("getIAMKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getAllAWSRoleTypes=function(e){var t=e.getDynamicValues?"allAwsRoleTypes?getDynamicValues=true":"allAwsRoleTypes";return this._doFetch(t,e,"GET").then(function(e){return e.roleTypes})},t.prototype.getAWSRoleTypes=function(e){return this._doFetch("getAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.getNonServiceAWSRoleTypes=function(e){return this._doFetch("getNonServiceAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.createRole=function(e){return this._doFetch("createRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.createNonServiceRole=function(e){return this._doFetch("createNonServiceRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.awsAccountRoles=function(e){return this._doFetch("awsAccountRoles?account="+e.account,e,"GET").then(function(e){return e.awsRoleList})},t.prototype.listAWSAccountRoles=function(e){return this._doFetch("listAWSAccountRoles",e).then(function(e){return JSON.parse(e.jsonAWSRoleList).map(function(e){return e.split("/").slice(-1)[0]})})},t.prototype.getAccountRole=function(t){return this._doFetch("getAccountRole",t).then(function(e){if(!e.roleExists)throw new Error("Role "+t.roleName+" does not exist in this account");return e.roleARN})},t.prototype.deleteRole=function(e){return this._doFetch("deleteRole",e).then(function(){return!0})},t.prototype.addRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e).then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.deleteRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e,"DELETE").then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.getUserAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/"+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserAccessByRole=function(e){var t=e.accountId;return this._doFetch("reports/users-by-role?accountId="+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserRoleAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/roles/"+t,e).then(function(e){return e.roles})},t.prototype.getAccountOwners=function(e){var t=e.accountId;return this._doFetch("userAccess/owners/"+t,e,"GET").then(function(e){return e.accountOwners})},t.prototype.createAccessKeys=function(e){return this._doFetch("accessKeys",e).then(function(e){return o(e,["iamUserArn","accessKey","secretKey","addedIAMUserToGroup"])})},t.prototype.deleteIAMUser=function(e){return this._doFetch("IAMUser",e,"DELETE").then(function(){return!0})},t.prototype.version=function(e){return this._doFetch("version",e,"GET").then(function(e){return o(e,["version"])})},t.prototype.getLoginRole=function(e){var t=e.accountId,n=e.role;return this._doFetch("loginRoles/id/"+t+"/"+n,null).then(function(e){return o(e,["account","role","iamKeyActive","maxKeyDuration"])})},t.prototype.getAccessToken=function(e){return this._doFetch("accessToken",e).then(function(e){return o(e,["accessToken","expiresIn"])})},t.prototype.getRefreshTokens=function(e){return this._doFetch("refreshTokens",e,"GET").then(function(e){return e.refreshTokens.map(function(e){return o(e,["clientId","id","userId","value"])})})},t.prototype.revoke=function(e){return this._doFetch("revoke",e).then(function(e){return"Success"==e.statusMessage})},t.prototype._doFetch=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n="POST");var o=Object.assign({},this.defaults,t),r={"Content-Type":"application/json","User-Agent":"AlksJS/1.11.4"};if(o.accessToken&&(r.Authorization="Bearer "+o.accessToken,delete o.accessToken),o.userid||o.password){console.error("The userid and password properties are deprecated and should be replaced with an access token");var s=this._base64Encode(o.userid+":"+o.password);r.Authorization="Basic "+s,delete o.userid,delete o.password}o.accessKey&&(r["ALKS-STS-Access-Key"]=o.accessKey,delete o.accessKey),o.secretKey&&(r["ALKS-STS-Secret-Key"]=o.secretKey,delete o.secretKey),o.sessionToken&&(r["ALKS-STS-Session-Token"]=o.sessionToken,delete o.sessionToken);var c=o._fetch(o.baseUrl+"/"+e,{method:n,headers:r,body:"GET"==n?void 0:JSON.stringify(o)}),i=c.then(function(e){return e.json()}).catch(function(){});return Promise.all([c,i]).then(function(e){var t=e[0],n=e[1];if(!t.ok)throw new u(t,n);return n})};var o=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})},u=function(r){function e(e,t){var n=Array.isArray(t.errors)?t.errors:[];e.statusText&&n.unshift(e.statusText);var o=n.join("; ");r.call(this,o),this.status=e.status,this.message=o,Object.assign(this,t)}return r&&(e.__proto__=r),(e.prototype=Object.create(r&&r.prototype)).constructor=e}(Error);return new t}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).alks=t()}(this,function(){"use strict";var n=window.fetch.bind(window),t=function(e,t){void 0===t&&(t={}),this.defaults=Object.assign({},t,{_fetch:n},e)};t.prototype._base64Encode=function(e){return void 0===e&&(e=""),btoa(e)},t.prototype.create=function(e){return new t(e,this.defaults)},t.prototype.getAccounts=function(e){return this._doFetch("getAccounts",e).then(function(t){return Object.keys(t.accountListRole).map(function(e){return{account:e,role:t.accountListRole[e][0].role,iamKeyActive:t.accountListRole[e][0].iamKeyActive,maxKeyDuration:t.accountListRole[e][0].maxKeyDuration,skypieaAccount:t.accountListRole[e][0].skypieaAccount}})})},t.prototype.getKeys=function(e){return this._doFetch("getKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getIAMKeys=function(e){return this._doFetch("getIAMKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getAllAWSRoleTypes=function(e){var t=e.getDynamicValues?"allAwsRoleTypes?getDynamicValues=true":"allAwsRoleTypes";return this._doFetch(t,e,"GET").then(function(e){return e.roleTypes})},t.prototype.getAWSRoleTypes=function(e){return this._doFetch("getAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.getNonServiceAWSRoleTypes=function(e){return this._doFetch("getNonServiceAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.createRole=function(e){return this._doFetch("createRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.createNonServiceRole=function(e){return this._doFetch("createNonServiceRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.awsAccountRoles=function(e){return this._doFetch("awsAccountRoles?account="+e.account,e,"GET").then(function(e){return e.awsRoleList})},t.prototype.listAWSAccountRoles=function(e){return this._doFetch("listAWSAccountRoles",e).then(function(e){return JSON.parse(e.jsonAWSRoleList).map(function(e){return e.split("/").slice(-1)[0]})})},t.prototype.getAccountRole=function(t){return this._doFetch("getAccountRole",t).then(function(e){if(!e.roleExists)throw new Error("Role "+t.roleName+" does not exist in this account");return e.roleARN})},t.prototype.deleteRole=function(e){return this._doFetch("deleteRole",e).then(function(){return!0})},t.prototype.addRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e).then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.deleteRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e,"DELETE").then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.getUserAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/"+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserAccessByRole=function(e){var t=e.accountId;return this._doFetch("reports/users-by-role?accountId="+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserRoleAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/roles/"+t,e).then(function(e){return e.roles})},t.prototype.getAccountOwners=function(e){var t=e.accountId;return this._doFetch("userAccess/owners/"+t,e,"GET").then(function(e){return e.accountOwners})},t.prototype.createAccessKeys=function(e){return this._doFetch("accessKeys",e).then(function(e){return o(e,["iamUserArn","accessKey","secretKey","addedIAMUserToGroup"])})},t.prototype.deleteIAMUser=function(e){return this._doFetch("IAMUser",e,"DELETE").then(function(){return!0})},t.prototype.version=function(e){return this._doFetch("version",e,"GET").then(function(e){return o(e,["version"])})},t.prototype.getLoginRole=function(e){var t=e.accountId,n=e.role;return this._doFetch("loginRoles/id/"+t+"/"+n,null,"GET").then(function(e){return o(e.loginRole,["account","role","iamKeyActive","maxKeyDuration"])})},t.prototype.getAccessToken=function(e){return this._doFetch("accessToken",e).then(function(e){return o(e,["accessToken","expiresIn"])})},t.prototype.getRefreshTokens=function(e){return this._doFetch("refreshTokens",e,"GET").then(function(e){return e.refreshTokens.map(function(e){return o(e,["clientId","id","userId","value"])})})},t.prototype.revoke=function(e){return this._doFetch("revoke",e).then(function(e){return"Success"==e.statusMessage})},t.prototype._doFetch=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n="POST");var o=Object.assign({},this.defaults,t),r={"Content-Type":"application/json","User-Agent":"AlksJS/1.11.4"};if(o.accessToken&&(r.Authorization="Bearer "+o.accessToken,delete o.accessToken),o.userid||o.password){console.error("The userid and password properties are deprecated and should be replaced with an access token");var s=this._base64Encode(o.userid+":"+o.password);r.Authorization="Basic "+s,delete o.userid,delete o.password}o.accessKey&&(r["ALKS-STS-Access-Key"]=o.accessKey,delete o.accessKey),o.secretKey&&(r["ALKS-STS-Secret-Key"]=o.secretKey,delete o.secretKey),o.sessionToken&&(r["ALKS-STS-Session-Token"]=o.sessionToken,delete o.sessionToken);var c=o._fetch(o.baseUrl+"/"+e,{method:n,headers:r,body:"GET"==n?void 0:JSON.stringify(o)}),i=c.then(function(e){return e.json()}).catch(function(){});return Promise.all([c,i]).then(function(e){var t=e[0],n=e[1];if(!t.ok)throw new u(t,n);return n})};var o=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})},u=function(r){function e(e,t){var n=Array.isArray(t.errors)?t.errors:[];e.statusText&&n.unshift(e.statusText);var o=n.join("; ");r.call(this,o),this.status=e.status,this.message=o,Object.assign(this,t)}return r&&(e.__proto__=r),(e.prototype=Object.create(r&&r.prototype)).constructor=e}(Error);return new t}); diff --git a/dist/alks.umd.js b/dist/alks.umd.js index a14770cb..53cbb879 100644 --- a/dist/alks.umd.js +++ b/dist/alks.umd.js @@ -713,7 +713,6 @@ * @param {Object} props - An object containing the following properties * @param {string} props.accountId - The 12-digit account ID associated with the custom role * @param {string} props.role - The user's role associated with the account - * @param {number} props.maxKeyDuration - The maximum key duration for this account * @returns {Promise} * @example * alks.getLoginRole({ @@ -725,7 +724,7 @@ 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']); }) + return this._doFetch(("loginRoles/id/" + accountId + "/" + role), null, 'GET').then(function (results) { return pick(results.loginRole, ['account', 'role', 'iamKeyActive', 'maxKeyDuration']); }) }; /** diff --git a/index.d.ts b/index.d.ts index 3dd457d5..5b077058 100644 --- a/index.d.ts +++ b/index.d.ts @@ -185,7 +185,6 @@ declare namespace ALKS { export interface GetLoginRoleProps { accountId: string; role: string; - maxKeyDuration: number; } export interface GetAccessTokenProps extends Partial { diff --git a/src/alks.js b/src/alks.js index 1af7ee8f..96634c6d 100755 --- a/src/alks.js +++ b/src/alks.js @@ -718,7 +718,6 @@ class alks { * @param {Object} props - An object containing the following properties * @param {string} props.accountId - The 12-digit account ID associated with the custom role * @param {string} props.role - The user's role associated with the account - * @param {number} props.maxKeyDuration - The maximum key duration for this account * @returns {Promise} * @example * alks.getLoginRole({ @@ -729,8 +728,8 @@ class alks { */ getLoginRole(props) { const {accountId, role} = props - return this._doFetch(`loginRoles/id/${accountId}/${role}`, null).then((results) => - pick(results, ['account', 'role', 'iamKeyActive', 'maxKeyDuration'])) + return this._doFetch(`loginRoles/id/${accountId}/${role}`, null, 'GET').then((results) => + pick(results.loginRole, ['account', 'role', 'iamKeyActive', 'maxKeyDuration'])) } /** diff --git a/test/test.js b/test/test.js index 4c4b2763..b08403b9 100755 --- a/test/test.js +++ b/test/test.js @@ -716,10 +716,12 @@ describe('alks.js', function() { const _fetch = fetchMock.sandbox().mock(`${baseUrl}/loginRoles/id/${accountId}/${role}`, { body: { - account, - role, - iamKeyActive, - maxKeyDuration + loginRole: { + account, + role, + iamKeyActive, + maxKeyDuration + } }, status: 200 })