From 5af26753eff2277025ae25eb25f598d06bf1feaf Mon Sep 17 00:00:00 2001 From: Andrew Mitchell Date: Tue, 21 Aug 2018 13:45:42 -0700 Subject: [PATCH] Released version 1.3.0 with SAT support --- build/index-node.js | 250 +++++++++++++++++++++++++--- build/index-web.js | 10 +- docs/index.html | 395 +++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 4 files changed, 628 insertions(+), 29 deletions(-) diff --git a/build/index-node.js b/build/index-node.js index f0809a1..9cbfb42 100644 --- a/build/index-node.js +++ b/build/index-node.js @@ -7834,6 +7834,214 @@ var TrueVaultClient = function () { return sendPasswordResetEmail; }() + + /** + * Link a Scoped Access Token to a Password Reset Flow. See https://docs.truevault.com/passwordresetflow#link-a-scoped-access-token-to-a-password-reset-flow + * @param {string} flowId + * @param {string} tokenId + * @returns {Promise.} + */ + + }, { + key: 'linkScopedAccessTokenToPasswordResetFlow', + value: function () { + var _ref67 = _asyncToGenerator(regeneratorRuntime.mark(function _callee67(flowId, tokenId) { + return regeneratorRuntime.wrap(function _callee67$(_context67) { + while (1) { + switch (_context67.prev = _context67.next) { + case 0: + _context67.next = 2; + return this.performJSONRequest('v1/password_reset_flows/' + flowId + '/link_sat', { + method: 'POST', + body: JSON.stringify({ + scoped_access_token_id: tokenId + }) + }); + + case 2: + return _context67.abrupt('return', _context67.sent); + + case 3: + case 'end': + return _context67.stop(); + } + } + }, _callee67, this); + })); + + function linkScopedAccessTokenToPasswordResetFlow(_x159, _x160) { + return _ref67.apply(this, arguments); + } + + return linkScopedAccessTokenToPasswordResetFlow; + }() + + /** + * Create a new Scoped Access Token. See: https://docs.truevault.com/scopedaccesstokens#create-a-scoped-access-token + * @param {string} name + * @param {Array} policy See https://docs.truevault.com/groups for policy definition documentation + * @param {Date} [notValidAfter] notValidAfter optional parameter specifying when the returned access token expires + * @param {number} [allowedUses] allowedUses optional parameter specifying number of allowed uses + * @returns {Promise.} + */ + + }, { + key: 'createScopedAccessToken', + value: function () { + var _ref68 = _asyncToGenerator(regeneratorRuntime.mark(function _callee68(name, policy, notValidAfter, allowedUses) { + var jsonPayload, response; + return regeneratorRuntime.wrap(function _callee68$(_context68) { + while (1) { + switch (_context68.prev = _context68.next) { + case 0: + jsonPayload = { + name: name, + policy: policy + }; + + + if (!!notValidAfter) { + jsonPayload['not_valid_after'] = notValidAfter.toISOString(); + } + + if (!!allowedUses) { + jsonPayload['allowed_uses'] = allowedUses; + } + + _context68.next = 5; + return this.performJSONRequest('v1/scoped_access_tokens', { + method: 'POST', + body: JSON.stringify(jsonPayload) + }); + + case 5: + response = _context68.sent; + return _context68.abrupt('return', response.scoped_access_token); + + case 7: + case 'end': + return _context68.stop(); + } + } + }, _callee68, this); + })); + + function createScopedAccessToken(_x161, _x162, _x163, _x164) { + return _ref68.apply(this, arguments); + } + + return createScopedAccessToken; + }() + + /** + * Get a Scoped Access Token. See https://docs.truevault.com/scopedaccesstokens#get-a-scoped-access-token + * @param {string} tokenId the token to get + * @returns {Promise.} + */ + + }, { + key: 'getScopedAccessToken', + value: function () { + var _ref69 = _asyncToGenerator(regeneratorRuntime.mark(function _callee69(tokenId) { + var response; + return regeneratorRuntime.wrap(function _callee69$(_context69) { + while (1) { + switch (_context69.prev = _context69.next) { + case 0: + _context69.next = 2; + return this.performJSONRequest('v1/scoped_access_tokens/' + tokenId); + + case 2: + response = _context69.sent; + return _context69.abrupt('return', response.scoped_access_token); + + case 4: + case 'end': + return _context69.stop(); + } + } + }, _callee69, this); + })); + + function getScopedAccessToken(_x165) { + return _ref69.apply(this, arguments); + } + + return getScopedAccessToken; + }() + + /** + * List all Scoped Access Tokens. See https://docs.truevault.com/scopedaccesstokens#list-scoped-access-tokens + * @returns {Promise.} + */ + + }, { + key: 'listScopedAccessTokens', + value: function () { + var _ref70 = _asyncToGenerator(regeneratorRuntime.mark(function _callee70() { + var response; + return regeneratorRuntime.wrap(function _callee70$(_context70) { + while (1) { + switch (_context70.prev = _context70.next) { + case 0: + _context70.next = 2; + return this.performJSONRequest('v1/scoped_access_tokens'); + + case 2: + response = _context70.sent; + return _context70.abrupt('return', response.data.items); + + case 4: + case 'end': + return _context70.stop(); + } + } + }, _callee70, this); + })); + + function listScopedAccessTokens() { + return _ref70.apply(this, arguments); + } + + return listScopedAccessTokens; + }() + + /** + * Delete a Scoped Access Token. See https://docs.truevault.com/scopedaccesstokens#delete-a-scoped-access-token + * @param {string} tokenId the token to delete + * @returns {Promise.} + */ + + }, { + key: 'deleteScopedAccessToken', + value: function () { + var _ref71 = _asyncToGenerator(regeneratorRuntime.mark(function _callee71(tokenId) { + return regeneratorRuntime.wrap(function _callee71$(_context71) { + while (1) { + switch (_context71.prev = _context71.next) { + case 0: + _context71.next = 2; + return this.performJSONRequest('v1/scoped_access_tokens/' + tokenId, { + method: 'DELETE' + }); + + case 2: + return _context71.abrupt('return', _context71.sent); + + case 3: + case 'end': + return _context71.stop(); + } + } + }, _callee71, this); + })); + + function deleteScopedAccessToken(_x166) { + return _ref71.apply(this, arguments); + } + + return deleteScopedAccessToken; + }() }, { key: 'accessToken', get: function get() { @@ -7857,29 +8065,29 @@ var TrueVaultClient = function () { }], [{ key: 'login', value: function () { - var _ref67 = _asyncToGenerator(regeneratorRuntime.mark(function _callee67(accountId, username, password, mfaCode, host, notValidAfter) { + var _ref72 = _asyncToGenerator(regeneratorRuntime.mark(function _callee72(accountId, username, password, mfaCode, host, notValidAfter) { var accessToken; - return regeneratorRuntime.wrap(function _callee67$(_context67) { + return regeneratorRuntime.wrap(function _callee72$(_context72) { while (1) { - switch (_context67.prev = _context67.next) { + switch (_context72.prev = _context72.next) { case 0: - _context67.next = 2; + _context72.next = 2; return TrueVaultClient.generateAccessToken(accountId, username, password, mfaCode, host, notValidAfter); case 2: - accessToken = _context67.sent; - return _context67.abrupt('return', new TrueVaultClient({ 'accessToken': accessToken }, host)); + accessToken = _context72.sent; + return _context72.abrupt('return', new TrueVaultClient({ 'accessToken': accessToken }, host)); case 4: case 'end': - return _context67.stop(); + return _context72.stop(); } } - }, _callee67, this); + }, _callee72, this); })); - function login(_x159, _x160, _x161, _x162, _x163, _x164) { - return _ref67.apply(this, arguments); + function login(_x167, _x168, _x169, _x170, _x171, _x172) { + return _ref72.apply(this, arguments); } return login; @@ -7900,11 +8108,11 @@ var TrueVaultClient = function () { }, { key: 'generateAccessToken', value: function () { - var _ref68 = _asyncToGenerator(regeneratorRuntime.mark(function _callee68(accountId, username, password, mfaCode, host, notValidAfter) { + var _ref73 = _asyncToGenerator(regeneratorRuntime.mark(function _callee73(accountId, username, password, mfaCode, host, notValidAfter) { var formData, tvClient, response; - return regeneratorRuntime.wrap(function _callee68$(_context68) { + return regeneratorRuntime.wrap(function _callee73$(_context73) { while (1) { - switch (_context68.prev = _context68.next) { + switch (_context73.prev = _context73.next) { case 0: formData = new tvFormData(); @@ -7919,26 +8127,26 @@ var TrueVaultClient = function () { } tvClient = new TrueVaultClient(null, host); - _context68.next = 9; + _context73.next = 9; return tvClient.performLegacyRequest('v1/auth/login', { method: 'POST', body: formData }); case 9: - response = _context68.sent; - return _context68.abrupt('return', response.user.access_token); + response = _context73.sent; + return _context73.abrupt('return', response.user.access_token); case 11: case 'end': - return _context68.stop(); + return _context73.stop(); } } - }, _callee68, this); + }, _callee73, this); })); - function generateAccessToken(_x165, _x166, _x167, _x168, _x169, _x170) { - return _ref68.apply(this, arguments); + function generateAccessToken(_x173, _x174, _x175, _x176, _x177, _x178) { + return _ref73.apply(this, arguments); } return generateAccessToken; @@ -27187,7 +27395,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ module.exports = { "name": "truevault", "description": "The official TrueVault JavaScript SDK", - "version": "1.2.1", + "version": "1.3.0", "repository": { "type": "git", "url": "https://github.com/truevault/truevault-js-sdk" diff --git a/build/index-web.js b/build/index-web.js index 90b40a5..3ba955d 100644 --- a/build/index-web.js +++ b/build/index-web.js @@ -1,4 +1,4 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TrueVaultClient=e():t.TrueVaultClient=e()}(this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="./build",r(r.s=314)}([function(t,e,r){var n=r(2),o=r(24),i=r(12),u=r(13),a=r(25),s=function(t,e,r){var c,f,h,p,l=t&s.F,d=t&s.G,v=t&s.S,g=t&s.P,m=t&s.B,y=d?n:v?n[e]||(n[e]={}):(n[e]||{}).prototype,b=d?o:o[e]||(o[e]={}),w=b.prototype||(b.prototype={});for(c in d&&(r=e),r)h=((f=!l&&y&&void 0!==y[c])?y:r)[c],p=m&&f?a(h,n):g&&"function"==typeof h?a(Function.call,h):h,y&&u(y,c,h,t&s.U),b[c]!=h&&i(b,c,p),g&&w[c]!=h&&(w[c]=h)};n.core=o,s.F=1,s.G=2,s.S=4,s.P=8,s.B=16,s.W=32,s.U=64,s.R=128,t.exports=s},function(t,e,r){var n=r(4);t.exports=function(t){if(!n(t))throw TypeError(t+" is not an object!");return t}},function(t,e){var r=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=r)},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,r){var n=r(58)("wks"),o=r(39),i=r(2).Symbol,u="function"==typeof i;(t.exports=function(t){return n[t]||(n[t]=u&&i[t]||(u?i:o)("Symbol."+t))}).store=n},function(t,e,r){t.exports=!r(3)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e,r){var n=r(1),o=r(94),i=r(23),u=Object.defineProperty;e.f=r(6)?Object.defineProperty:function(t,e,r){if(n(t),e=i(e,!0),n(r),o)try{return u(t,e,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(t[e]=r.value),t}},function(t,e,r){var n=r(30),o=Math.min;t.exports=function(t){return t>0?o(n(t),9007199254740991):0}},function(t,e,r){var n=r(19);t.exports=function(t){return Object(n(t))}},function(t,e){var r={}.hasOwnProperty;t.exports=function(t,e){return r.call(t,e)}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e,r){var n=r(7),o=r(29);t.exports=r(6)?function(t,e,r){return n.f(t,e,o(1,r))}:function(t,e,r){return t[e]=r,t}},function(t,e,r){var n=r(2),o=r(12),i=r(10),u=r(39)("src"),a=Function.toString,s=(""+a).split("toString");r(24).inspectSource=function(t){return a.call(t)},(t.exports=function(t,e,r,a){var c="function"==typeof r;c&&(i(r,"name")||o(r,"name",e)),t[e]!==r&&(c&&(i(r,u)||o(r,u,t[e]?""+t[e]:s.join(String(e)))),t===n?t[e]=r:a?t[e]?t[e]=r:o(t,e,r):(delete t[e],o(t,e,r)))})(Function.prototype,"toString",function(){return"function"==typeof this&&this[u]||a.call(this)})},function(t,e,r){var n=r(0),o=r(3),i=r(19),u=/"/g,a=function(t,e,r,n){var o=String(i(t)),a="<"+e;return""!==r&&(a+=" "+r+'="'+String(n).replace(u,""")+'"'),a+">"+o+""};t.exports=function(t,e){var r={};r[t]=e(a),n(n.P+n.F*o(function(){var e=""[t]('"');return e!==e.toLowerCase()||e.split('"').length>3}),"String",r)}},function(t,e,r){var n=r(46),o=r(19);t.exports=function(t){return n(o(t))}},function(t,e,r){var n=r(47),o=r(29),i=r(15),u=r(23),a=r(10),s=r(94),c=Object.getOwnPropertyDescriptor;e.f=r(6)?c:function(t,e){if(t=i(t),e=u(e,!0),s)try{return c(t,e)}catch(t){}if(a(t,e))return o(!n.f.call(t,e),t[e])}},function(t,e,r){var n=r(10),o=r(9),i=r(75)("IE_PROTO"),u=Object.prototype;t.exports=Object.getPrototypeOf||function(t){return t=o(t),n(t,i)?t[i]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?u:null}},function(t,e){var r={}.toString;t.exports=function(t){return r.call(t).slice(8,-1)}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,r){var n=r(3);t.exports=function(t,e){return!!t&&n(function(){e?t.call(null,function(){},1):t.call(null)})}},function(t,e,r){var n=r(25),o=r(46),i=r(9),u=r(8),a=r(127);t.exports=function(t,e){var r=1==t,s=2==t,c=3==t,f=4==t,h=6==t,p=5==t||h,l=e||a;return function(e,a,d){for(var v,g,m=i(e),y=o(m),b=n(a,d,3),w=u(y.length),_=0,x=r?l(e,w):s?l(e,0):void 0;w>_;_++)if((p||_ in y)&&(g=b(v=y[_],_,m),t))if(r)x[_]=g;else if(g)switch(t){case 3:return!0;case 5:return v;case 6:return _;case 2:x.push(v)}else if(f)return!1;return h?-1:c||f?f:x}}},function(t,e,r){var n=r(0),o=r(24),i=r(3);t.exports=function(t,e){var r=(o.Object||{})[t]||Object[t],u={};u[t]=e(r),n(n.S+n.F*i(function(){r(1)}),"Object",u)}},function(t,e,r){var n=r(4);t.exports=function(t,e){if(!n(t))return t;var r,o;if(e&&"function"==typeof(r=t.toString)&&!n(o=r.call(t)))return o;if("function"==typeof(r=t.valueOf)&&!n(o=r.call(t)))return o;if(!e&&"function"==typeof(r=t.toString)&&!n(o=r.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},function(t,e){var r=t.exports={version:"2.4.0"};"number"==typeof __e&&(__e=r)},function(t,e,r){var n=r(11);t.exports=function(t,e,r){if(n(t),void 0===e)return t;switch(r){case 1:return function(r){return t.call(e,r)};case 2:return function(r,n){return t.call(e,r,n)};case 3:return function(r,n,o){return t.call(e,r,n,o)}}return function(){return t.apply(e,arguments)}}},function(t,e,r){var n=r(110),o=r(0),i=r(58)("metadata"),u=i.store||(i.store=new(r(113))),a=function(t,e,r){var o=u.get(t);if(!o){if(!r)return;u.set(t,o=new n)}var i=o.get(e);if(!i){if(!r)return;o.set(e,i=new n)}return i};t.exports={store:u,map:a,has:function(t,e,r){var n=a(e,r,!1);return void 0!==n&&n.has(t)},get:function(t,e,r){var n=a(e,r,!1);return void 0===n?void 0:n.get(t)},set:function(t,e,r,n){a(r,n,!0).set(t,e)},keys:function(t,e){var r=a(t,e,!1),n=[];return r&&r.forEach(function(t,e){n.push(e)}),n},key:function(t){return void 0===t||"symbol"==typeof t?t:String(t)},exp:function(t){o(o.S,"Reflect",t)}}},function(t,e,r){"use strict";if(r(6)){var n=r(32),o=r(2),i=r(3),u=r(0),a=r(59),s=r(82),c=r(25),f=r(31),h=r(29),p=r(12),l=r(36),d=r(30),v=r(8),g=r(38),m=r(23),y=r(10),b=r(107),w=r(45),_=r(4),x=r(9),S=r(67),R=r(33),k=r(17),E=r(34).f,A=r(84),P=r(39),O=r(5),T=r(21),j=r(49),I=r(76),F=r(85),L=r(42),U=r(55),N=r(37),M=r(60),z=r(87),C=r(7),B=r(16),q=C.f,D=B.f,Q=o.RangeError,Y=o.TypeError,J=o.Uint8Array,W=Array.prototype,H=s.ArrayBuffer,V=s.DataView,$=T(0),G=T(2),Z=T(3),K=T(4),X=T(5),tt=T(6),et=j(!0),rt=j(!1),nt=F.values,ot=F.keys,it=F.entries,ut=W.lastIndexOf,at=W.reduce,st=W.reduceRight,ct=W.join,ft=W.sort,ht=W.slice,pt=W.toString,lt=W.toLocaleString,dt=O("iterator"),vt=O("toStringTag"),gt=P("typed_constructor"),mt=P("def_constructor"),yt=a.CONSTR,bt=a.TYPED,wt=a.VIEW,_t=T(1,function(t,e){return At(I(t,t[mt]),e)}),xt=i(function(){return 1===new J(new Uint16Array([1]).buffer)[0]}),St=!!J&&!!J.prototype.set&&i(function(){new J(1).set({})}),Rt=function(t,e){if(void 0===t)throw Y("Wrong length!");var r=+t,n=v(t);if(e&&!b(r,n))throw Q("Wrong length!");return n},kt=function(t,e){var r=d(t);if(r<0||r%e)throw Q("Wrong offset!");return r},Et=function(t){if(_(t)&&bt in t)return t;throw Y(t+" is not a typed array!")},At=function(t,e){if(!(_(t)&> in t))throw Y("It is not a typed array constructor!");return new t(e)},Pt=function(t,e){return Ot(I(t,t[mt]),e)},Ot=function(t,e){for(var r=0,n=e.length,o=At(t,n);n>r;)o[r]=e[r++];return o},Tt=function(t,e,r){q(t,e,{get:function(){return this._d[r]}})},jt=function(t){var e,r,n,o,i,u,a=x(t),s=arguments.length,f=s>1?arguments[1]:void 0,h=void 0!==f,p=A(a);if(void 0!=p&&!S(p)){for(u=p.call(a),n=[],e=0;!(i=u.next()).done;e++)n.push(i.value);a=n}for(h&&s>2&&(f=c(f,arguments[2],2)),e=0,r=v(a.length),o=At(this,r);r>e;e++)o[e]=h?f(a[e],e):a[e];return o},It=function(){for(var t=0,e=arguments.length,r=At(this,e);e>t;)r[t]=arguments[t++];return r},Ft=!!J&&i(function(){lt.call(new J(1))}),Lt=function(){return lt.apply(Ft?ht.call(Et(this)):Et(this),arguments)},Ut={copyWithin:function(t,e){return z.call(Et(this),t,e,arguments.length>2?arguments[2]:void 0)},every:function(t){return K(Et(this),t,arguments.length>1?arguments[1]:void 0)},fill:function(t){return M.apply(Et(this),arguments)},filter:function(t){return Pt(this,G(Et(this),t,arguments.length>1?arguments[1]:void 0))},find:function(t){return X(Et(this),t,arguments.length>1?arguments[1]:void 0)},findIndex:function(t){return tt(Et(this),t,arguments.length>1?arguments[1]:void 0)},forEach:function(t){$(Et(this),t,arguments.length>1?arguments[1]:void 0)},indexOf:function(t){return rt(Et(this),t,arguments.length>1?arguments[1]:void 0)},includes:function(t){return et(Et(this),t,arguments.length>1?arguments[1]:void 0)},join:function(t){return ct.apply(Et(this),arguments)},lastIndexOf:function(t){return ut.apply(Et(this),arguments)},map:function(t){return _t(Et(this),t,arguments.length>1?arguments[1]:void 0)},reduce:function(t){return at.apply(Et(this),arguments)},reduceRight:function(t){return st.apply(Et(this),arguments)},reverse:function(){for(var t,e=Et(this).length,r=Math.floor(e/2),n=0;n1?arguments[1]:void 0)},sort:function(t){return ft.call(Et(this),t)},subarray:function(t,e){var r=Et(this),n=r.length,o=g(t,n);return new(I(r,r[mt]))(r.buffer,r.byteOffset+o*r.BYTES_PER_ELEMENT,v((void 0===e?n:g(e,n))-o))}},Nt=function(t,e){return Pt(this,ht.call(Et(this),t,e))},Mt=function(t){Et(this);var e=kt(arguments[1],1),r=this.length,n=x(t),o=v(n.length),i=0;if(o+e>r)throw Q("Wrong length!");for(;i255?255:255&n),o.v[d](r*e+o.o,n,xt)}(this,r,t)},enumerable:!0})};b?(g=r(function(t,r,n,o){f(t,g,c,"_d");var i,u,a,s,h=0,l=0;if(_(r)){if(!(r instanceof H||"ArrayBuffer"==(s=w(r))||"SharedArrayBuffer"==s))return bt in r?Ot(g,r):jt.call(g,r);i=r,l=kt(n,e);var d=r.byteLength;if(void 0===o){if(d%e)throw Q("Wrong length!");if((u=d-l)<0)throw Q("Wrong length!")}else if((u=v(o)*e)+l>d)throw Q("Wrong length!");a=u/e}else a=Rt(r,!0),i=new H(u=a*e);for(p(t,"_d",{b:i,o:l,l:u,e:a,v:new V(i)});h0?n:r)(t)}},function(t,e){t.exports=function(t,e,r,n){if(!(t instanceof e)||void 0!==n&&n in t)throw TypeError(r+": incorrect invocation!");return t}},function(t,e){t.exports=!1},function(t,e,r){var n=r(1),o=r(100),i=r(63),u=r(75)("IE_PROTO"),a=function(){},s=function(){var t,e=r(62)("iframe"),n=i.length;for(e.style.display="none",r(65).appendChild(e),e.src="javascript:",(t=e.contentWindow.document).open(),t.write("