Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@accounts/client

Package Overview
Dependencies
Maintainers
1
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accounts/client - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

lib/AccountsClient.js

21

lib/index.js

@@ -1,1 +0,20 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@accounts/common"),require("immutable"),require("jwt-decode"),require("lodash"),require("redux"),require("redux-immutable")):"function"==typeof define&&define.amd?define(["@accounts/common","immutable","jwt-decode","lodash","redux","redux-immutable"],t):"object"==typeof exports?exports["@accounts/client"]=t(require("@accounts/common"),require("immutable"),require("jwt-decode"),require("lodash"),require("redux"),require("redux-immutable")):e["@accounts/client"]=t(e["@accounts/common"],e.immutable,e["jwt-decode"],e.lodash,e.redux,e["redux-immutable"])}(this,function(e,t,r,n,o,s){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.config=t.AccountsClient=void 0;var o=r(1),s=n(o),i=r(2),a=n(i);t.default=s.default,t.AccountsClient=o.AccountsClient,t.config=a.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,r){function n(o,s){try{var i=t[o](s),a=i.value}catch(e){return void r(e)}return i.done?void e(a):Promise.resolve(a).then(function(e){n("next",e)},function(e){n("throw",e)})}return n("next")})}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.AccountsClient=void 0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=r(9),c=r(8),l=n(c),f=r(3),d=r(2),h=n(d),p=r(5),g=n(p),m=r(6),v=n(m),k=function(e){return(0,u.has)(e,"user")||(0,u.has)(e,"email")||(0,u.has)(e,"id")},w="accounts:accessToken",x="accounts:refreshToken",y=function(e,t){return(0,u.isString)(t.localStoragePrefix)&&t.localStoragePrefix.length>0?t.localStoragePrefix+":"+e:e},b=t.AccountsClient=function(){function e(t,r){if(s(this,e),this.options=t,!r)throw new f.AccountsError({message:"A REST or GraphQL transport is required"});this.transport=r;var n=t.reduxLogger?[t.reduxLogger]:[];this.store=(0,g.default)({reducers:{accounts:v.default},middleware:n})}return a(e,[{key:"getState",value:function(){return this.store.getState().get("accounts")}},{key:"user",value:function(){return this.getState().get("user").toJS()}},{key:"tokens",value:function(){return{accessToken:localStorage.getItem(y(w,this.options)),refreshToken:localStorage.getItem(y(x,this.options))}}},{key:"clearTokens",value:function(){localStorage.removeItem(y(w,this.options)),localStorage.removeItem(y(x,this.options))}},{key:"clearUser",value:function(){this.store.dispatch((0,m.clearUser)())}},{key:"resumeSession",value:function(){return this.refreshSession()}},{key:"refreshSession",value:function(){function e(){return t.apply(this,arguments)}var t=o(regeneratorRuntime.mark(function e(){var t,r,n,o,s,i;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.tokens(),r=t.accessToken,n=t.refreshToken,!r||!n){e.next=25;break}if(e.prev=2,o=(0,l.default)(n),s=Date.now()/1e3,!(o.exp<s)){e.next=10;break}this.clearTokens(),this.clearUser(),e.next=16;break;case 10:return e.next=12,this.transport.refreshTokens(r,n);case 12:i=e.sent,localStorage.setItem(y(w,this.options),i.tokens.accessToken),localStorage.setItem(y(x,this.options),i.tokens.refreshToken),this.store.dispatch((0,m.setUser)(i.user));case 16:e.next=23;break;case 18:throw e.prev=18,e.t0=e.catch(2),this.clearTokens(),this.clearUser(),new f.AccountsError({message:"falsy token provided"});case 23:e.next=27;break;case 25:this.clearTokens(),this.clearUser();case 27:case"end":return e.stop()}},e,this,[[2,18]])}));return e}()},{key:"createUser",value:function(){function e(e,r){return t.apply(this,arguments)}var t=o(regeneratorRuntime.mark(function e(t,r){var n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&void 0!==t.password){e.next=2;break}throw new f.AccountsError({message:"Unrecognized options for create user request [400]"});case 2:if(f.validators.validatePassword(t.password)){e.next=4;break}throw new f.AccountsError({message:"Password is required"});case 4:if(f.validators.validateUsername(t.username)||f.validators.validateEmail(t.email)){e.next=6;break}throw new f.AccountsError({message:"Username or Email is required"});case 6:return e.prev=6,e.next=9,this.transport.createUser(t);case 9:return n=e.sent,r&&(0,u.isFunction)(r)&&r(),e.next=13,this.loginWithPassword({id:n},t.password);case 13:e.next=19;break;case 15:throw e.prev=15,e.t0=e.catch(6),r&&(0,u.isFunction)(r)&&r(e.t0),new f.AccountsError({message:e.t0.message});case 19:case"end":return e.stop()}},e,this,[[6,15]])}));return e}()},{key:"loginWithPassword",value:function(){function e(e,r,n){return t.apply(this,arguments)}var t=o(regeneratorRuntime.mark(function e(t,r,n){var o;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r&&t){e.next=2;break}throw new f.AccountsError({message:"Unrecognized options for login request [400]"});case 2:if(((0,u.isString)(t)||k(t))&&(0,u.isString)(r)){e.next=4;break}throw new f.AccountsError({message:"Match failed [400]"});case 4:return this.store.dispatch((0,m.loggingIn)(!0)),e.prev=5,e.next=8,this.transport.loginWithPassword(t,r);case 8:o=e.sent,localStorage.setItem(y(w,this.options),o.tokens.accessToken),localStorage.setItem(y(x,this.options),o.tokens.refreshToken),this.store.dispatch((0,m.setUser)(o.user)),this.options.onSignedInHook(),n&&(0,u.isFunction)(n)&&n(),e.next=20;break;case 16:throw e.prev=16,e.t0=e.catch(5),n&&(0,u.isFunction)(n)&&n(e.t0),new f.AccountsError({message:e.t0.message});case 20:this.store.dispatch((0,m.loggingIn)(!1));case 21:case"end":return e.stop()}},e,this,[[5,16]])}));return e}()},{key:"loggingIn",value:function(){return this.getState().get("loggingIn")}},{key:"isLoading",value:function(){return this.getState().get("isLoading")}},{key:"logout",value:function(){function e(e){return t.apply(this,arguments)}var t=o(regeneratorRuntime.mark(function e(t){var r,n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=this.tokens(),n=r.accessToken,e.next=4,this.transport.logout(n);case 4:this.clearTokens(),this.store.dispatch((0,m.clearUser)()),t&&(0,u.isFunction)(t)&&t(),this.options.onSignedOutHook(),e.next=14;break;case 10:throw e.prev=10,e.t0=e.catch(0),t&&(0,u.isFunction)(t)&&t(e.t0),new f.AccountsError({message:e.t0.message});case 14:case"end":return e.stop()}},e,this,[[0,10]])}));return e}()}]),e}(),S={instance:b,ui:{},config:function(e,t){this.instance=new b(i({},h.default,e),t)},user:function(){return this.instance.user()},options:function(){return this.instance.options},createUser:function(e,t){return this.instance.createUser(e,t)},loginWithPassword:function(e,t,r){return this.instance.loginWithPassword(e,t,r)},loggingIn:function(){return this.instance.loggingIn()},isLoading:function(){return this.instance.isLoading()},logout:function(e){return this.instance.logout(e)},tokens:function(){return this.instance.tokens()},resumeSession:function(){return this.instance.resumeSession()},refreshSession:function(){return this.instance.refreshSession()}};t.default=S,"undefined"!=typeof window&&(window.onload=o(regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!S.instance){e.next=3;break}return e.next=3,S.resumeSession();case 3:case"end":return e.stop()}},e,void 0)})))},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},s=r(3),i=r(1),a=n(i),u=r(7),c=n(u);t.default=o({},s.config,{reduxLogger:null,server:"",localStoragePrefix:"",title:"",requestPermissions:[],requestOfflineToken:{},forceApprovalPrompt:{},requireEmailVerification:!1,loginPath:"/",signUpPath:null,resetPasswordPath:null,profilePath:"/",changePasswordPath:null,homePath:"/",onEnrollAccountHook:function(){return(0,c.default)(a.default.options().loginPath)},onResetPasswordHook:function(){return(0,c.default)(a.default.options().loginPath)},onVerifyEmailHook:function(){return(0,c.default)(a.default.options().profilePath)},onSignedInHook:function(){return(0,c.default)(a.default.options().homePath)},onSignedOutHook:function(){return(0,c.default)(a.default.options().homePath)},loginOnSignUp:!0})},function(e,t){e.exports=require("@accounts/common")},function(e,t){e.exports=require("immutable")},function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0});var o=r(10),s=r(4),i=r(11);t.default=function(e){var t=e.reducers,r=void 0===t?{}:t,a=e.middleware,u=void 0===a?[]:a,c=e.state,l=void 0===c?(0,s.Map)():c;return(0,o.createStore)((0,i.combineReducers)(r),l,(0,o.compose)(o.applyMiddleware.apply(void 0,n(u))))}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.clearUser=t.setUser=t.loggingIn=void 0;var n=r(4),o="js-accounts/",s=o+"LOGIN",i=o+"SET_USER",a=o+"CLEAR_USER",u=o+"LOGGING_IN",c=(0,n.Map)({isLoading:!1,user:(0,n.Map)(),loggingIn:!1}),l=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:c,t=arguments[1],r=e;switch(t.type){case s:break;case i:var o=t.payload.user;return e.set("user",(0,n.Map)(o));case a:return e.set("user",(0,n.Map)());case u:var l=t.payload.isLoggingIn;return e.set("loggingIn",l)}return r};t.default=l;t.loggingIn=function(e){return{type:u,payload:{isLoggingIn:e}}},t.setUser=function(e){return{type:i,payload:{user:e}}},t.clearUser=function(){return{type:a}}},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=r(1),s=n(o);t.default=function(e){return s.default.options().history.push(e)}},function(e,t){e.exports=require("jwt-decode")},function(e,t){e.exports=require("lodash")},function(e,t){e.exports=require("redux")},function(e,t){e.exports=require("redux-immutable")}])});
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.config = exports.AccountsClient = undefined;
var _AccountsClient = require('./AccountsClient');
var _AccountsClient2 = _interopRequireDefault(_AccountsClient);
var _config = require('./config');
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _AccountsClient2.default;
exports.AccountsClient = _AccountsClient.AccountsClient;
exports.config = _config2.default;

6

package.json
{
"name": "@accounts/client",
"version": "0.0.1",
"version": "0.0.2",
"description": "Fullstack authentication and accounts-management",

@@ -11,3 +11,3 @@ "main": "lib/index.js",

"start": "webpack -p --config --progress --watch",
"compile": "webpack -p --config --progress",
"compile": "babel ./src --out-dir ./lib",
"flow:check": "flow check",

@@ -74,3 +74,3 @@ "prepublish": "npm run compile",

"dependencies": {
"@accounts/common": "^0.0.1",
"@accounts/common": "^0.0.2",
"apollo-errors": "^1.2.1",

@@ -77,0 +77,0 @@ "immutable": "^3.8.1",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc