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

@accounts/client

Package Overview
Dependencies
Maintainers
5
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.19.0 to 0.19.1-alpha.2.17

16

lib/accounts-client.d.ts

@@ -1,2 +0,2 @@

import { LoginResult, Tokens, ImpersonationResult, User } from '@accounts/types';
import { LoginResult, MFALoginResult, Tokens, ImpersonationResult, User } from '@accounts/types';
import { TransportInterface } from './transport-interface';

@@ -22,2 +22,8 @@ import { AccountsClientOptions } from './types';

/**
* Authenticate the user with a specific service (not creating a session)
*/
authenticateWithService(service: string, credentials: {
[key: string]: any;
}): Promise<boolean>;
/**
* Login the user with a specific service

@@ -27,8 +33,12 @@ */

[key: string]: any;
}): Promise<LoginResult>;
}): Promise<LoginResult | Omit<MFALoginResult, 'mfaToken'>>;
/**
* Performs the mfa needed challenge and logs in afterwards
*/
performMfaChallenge(challenge: string, params: any): Promise<LoginResult>;
/**
* Refresh the user session
* If the tokens have expired try to refresh them
*/
refreshSession(): Promise<Tokens | null>;
refreshSession(force?: boolean): Promise<Tokens | null>;
/**

@@ -35,0 +45,0 @@ * Impersonate to another user.

@@ -10,2 +10,3 @@ "use strict";

TokenKey["RefreshToken"] = "refreshToken";
TokenKey["MfaToken"] = "mfaToken";
TokenKey["OriginalAccessToken"] = "originalAccessToken";

@@ -99,2 +100,12 @@ TokenKey["OriginalRefreshToken"] = "originalRefreshToken";

/**
* Authenticate the user with a specific service (not creating a session)
*/
AccountsClient.prototype.authenticateWithService = function (service, credentials) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.transport.authenticateWithService(service, credentials)];
});
});
};
/**
* Login the user with a specific service

@@ -110,6 +121,12 @@ */

response = _a.sent();
if (!response.tokens) return [3 /*break*/, 3];
return [4 /*yield*/, this.setTokens(response.tokens)];
case 2:
_a.sent();
return [2 /*return*/, response];
return [3 /*break*/, 5];
case 3: return [4 /*yield*/, this.storage.setItem(this.getTokenKey(TokenKey.MfaToken), response.mfaToken)];
case 4:
_a.sent();
_a.label = 5;
case 5: return [2 /*return*/, response];
}

@@ -120,6 +137,35 @@ });

/**
* Performs the mfa needed challenge and logs in afterwards
*/
AccountsClient.prototype.performMfaChallenge = function (challenge, params) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var mfaToken, loginToken, result;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.storage.getItem(this.getTokenKey(TokenKey.MfaToken))];
case 1:
mfaToken = _a.sent();
if (!mfaToken) {
throw new Error('mfaToken is not available in storage');
}
return [4 /*yield*/, this.transport.performMfaChallenge(challenge, mfaToken, params)];
case 2:
loginToken = _a.sent();
return [4 /*yield*/, this.loginWithService('mfa', { mfaToken: mfaToken, loginToken: loginToken })];
case 3:
result = _a.sent();
return [4 /*yield*/, this.storage.removeItem(this.getTokenKey(TokenKey.MfaToken))];
case 4:
_a.sent();
return [2 /*return*/, result];
}
});
});
};
/**
* Refresh the user session
* If the tokens have expired try to refresh them
*/
AccountsClient.prototype.refreshSession = function () {
AccountsClient.prototype.refreshSession = function (force) {
if (force === void 0) { force = false; }
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -138,3 +184,3 @@ var tokens, isAccessTokenExpired, isRefreshTokenExpired, refreshedSession, err_1;

isRefreshTokenExpired = utils_1.isTokenExpired(tokens.refreshToken);
if (!(isAccessTokenExpired && !isRefreshTokenExpired)) return [3 /*break*/, 5];
if (!((force || isAccessTokenExpired) && !isRefreshTokenExpired)) return [3 /*break*/, 5];
return [4 /*yield*/, this.transport.refreshTokens(tokens.accessToken, tokens.refreshToken)];

@@ -141,0 +187,0 @@ case 3:

19

lib/token-storage-local.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
exports.tokenStorageLocal = {
setItem: function (key, value) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, localStorage.setItem(key, value)];
});
});
return localStorage.setItem(key, value);
},
getItem: function (key) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, localStorage.getItem(key)];
});
});
return localStorage.getItem(key);
},
removeItem: function (key) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, localStorage.removeItem(key)];
});
});
return localStorage.removeItem(key);
},
};
//# sourceMappingURL=token-storage-local.js.map

@@ -1,2 +0,2 @@

import { LoginResult, ImpersonationResult, CreateUser, User } from '@accounts/types';
import { LoginResult, MFALoginResult, ImpersonationResult, CreateUser, User } from '@accounts/types';
import { AccountsClient } from './accounts-client';

@@ -6,5 +6,9 @@ export interface TransportInterface {

createUser(user: CreateUser): Promise<string>;
authenticateWithService(service: string, authenticateParams: {
[key: string]: string | object;
}): Promise<boolean>;
loginWithService(service: string, authenticateParams: {
[key: string]: string | object;
}): Promise<LoginResult>;
}): Promise<LoginResult | MFALoginResult>;
performMfaChallenge(challenge: string, mfaToken: string, params: any): Promise<string>;
logout(): Promise<void>;

@@ -11,0 +15,0 @@ getUser(): Promise<User>;

@@ -0,5 +1,7 @@

declare type ValueOrPromise<T> = T | Promise<T>;
export interface TokenStorage {
setItem(key: string, value: string): Promise<void>;
getItem(key: string): Promise<string | null>;
removeItem(key: string): Promise<void>;
setItem(key: string, value: string): ValueOrPromise<void>;
getItem(key: string): ValueOrPromise<string | null>;
removeItem(key: string): ValueOrPromise<void>;
}
export {};
{
"name": "@accounts/client",
"version": "0.19.0",
"version": "0.19.1-alpha.2.17+1d0a3901",
"description": "Fullstack authentication and accounts-management",

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

"@types/jwt-decode": "2.2.1",
"@types/node": "12.7.2",
"@types/node": "12.7.4",
"jest": "24.9.0",

@@ -57,7 +57,7 @@ "jest-localstorage-mock": "2.4.0",

"dependencies": {
"@accounts/types": "^0.19.0",
"@accounts/types": "^0.19.1-alpha.2.17+1d0a3901",
"jwt-decode": "2.2.0",
"tslib": "1.10.0"
},
"gitHead": "c0a7905161c702350efd4f7a622c55ede495a42b"
"gitHead": "1d0a3901760c599054c0ccdd3bcb0443e854646a"
}

Sorry, the diff of this file is not supported yet

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