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

supertokens-website

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supertokens-website - npm Package Compare versions

Comparing version 9.0.1 to 9.0.2

lib/build/axiosError.d.ts

9

CHANGELOG.md

@@ -7,2 +7,11 @@ # Changelog

## [9.0.2] - 2021-10-01
### Fixes
- Moved axios to dev dependency
- Fixed axios refresh error test
### Changes
- Using fetch instead of axios to call the refresh API
## [9.0.1] - 2021-10-01

@@ -9,0 +18,0 @@

246

lib/build/axios.js

@@ -146,17 +146,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
/* Copyright (c) 2020, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
var axios_1 = require("axios");
var axiosError_1 = require("./axiosError");
var fetch_1 = require("./fetch");

@@ -409,4 +395,2 @@ var processState_1 = require("./processState");

var doNotDoInterception,
axiosFetch,
throwError,
returnObj,

@@ -421,3 +405,4 @@ preRequestIdToken,

idRefreshToken,
retry,
refreshResult,
_b,
antiCsrfToken,

@@ -427,6 +412,6 @@ tok,

err_1,
retry;
var _this = this;
return __generator(this, function(_b) {
switch (_b.label) {
refreshResult,
_c;
return __generator(this, function(_d) {
switch (_d.label) {
case 0:

@@ -467,55 +452,17 @@ if (!fetch_1.default.initCalled) {

case 1:
return [2 /*return*/, _b.sent()];
return [2 /*return*/, _d.sent()];
case 2:
axiosFetch = function(url, config) {
return __awaiter(_this, void 0, void 0, function() {
var res;
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
return [
4 /*yield*/,
axios_1.default(
__assign(
{
url: url,
validateStatus: null,
withCredentials: config && config.credentials === "include",
data: config ? config.body : undefined
},
config,
{ method: config ? config.method : undefined }
)
)
];
case 1:
res = _a.sent();
return [
2 /*return*/,
new Response(res.data, {
status: res.status,
statusText: res.statusText,
headers: new Headers(res.headers)
})
];
}
});
});
};
_b.label = 3;
_d.trys.push([2, , 36, 41]);
returnObj = undefined;
_d.label = 3;
case 3:
_b.trys.push([3, , 28, 33]);
throwError = false;
returnObj = undefined;
_b.label = 4;
if (!true) return [3 /*break*/, 35];
return [4 /*yield*/, fetch_1.getIdRefreshToken(true)];
case 4:
if (!true) return [3 /*break*/, 27];
return [4 /*yield*/, fetch_1.getIdRefreshToken(true)];
case 5:
preRequestIdToken = _b.sent();
preRequestIdToken = _d.sent();
configWithAntiCsrf = config;
if (!(preRequestIdToken.status === "EXISTS")) return [3 /*break*/, 7];
if (!(preRequestIdToken.status === "EXISTS")) return [3 /*break*/, 6];
return [4 /*yield*/, fetch_1.AntiCsrfToken.getToken(preRequestIdToken.token)];
case 6:
antiCsrfToken = _b.sent();
case 5:
antiCsrfToken = _d.sent();
if (antiCsrfToken !== undefined) {

@@ -531,4 +478,4 @@ configWithAntiCsrf = __assign({}, configWithAntiCsrf, {

}
_b.label = 7;
case 7:
_d.label = 6;
case 6:
if (

@@ -549,5 +496,5 @@ fetch_1.default.config.autoAddCredentials &&

});
_b.label = 8;
case 8:
_b.trys.push([8, 22, , 26]);
_d.label = 7;
case 7:
_d.trys.push([7, 26, , 34]);
localPrevError = prevError;

@@ -560,53 +507,66 @@ localPrevResponse = prevResponse;

}
if (!(localPrevResponse === undefined)) return [3 /*break*/, 10];
if (!(localPrevResponse === undefined)) return [3 /*break*/, 9];
return [4 /*yield*/, httpCall(configWithAntiCsrf)];
case 8:
_a = _d.sent();
return [3 /*break*/, 10];
case 9:
_a = _b.sent();
return [3 /*break*/, 11];
_a = localPrevResponse;
_d.label = 10;
case 10:
_a = localPrevResponse;
_b.label = 11;
case 11:
response = _a;
idRefreshToken = response.headers["id-refresh-token"];
if (!(idRefreshToken !== undefined)) return [3 /*break*/, 13];
if (!(idRefreshToken !== undefined)) return [3 /*break*/, 12];
return [4 /*yield*/, fetch_1.setIdRefreshToken(idRefreshToken, response.status)];
case 11:
_d.sent();
_d.label = 12;
case 12:
_b.sent();
_b.label = 13;
if (!(response.status === fetch_1.default.config.sessionExpiredStatusCode))
return [3 /*break*/, 19];
return [4 /*yield*/, fetch_1.onUnauthorisedResponse(preRequestIdToken)];
case 13:
if (!(response.status === fetch_1.default.config.sessionExpiredStatusCode))
return [3 /*break*/, 15];
return [4 /*yield*/, fetch_1.handleUnauthorised(preRequestIdToken, axiosFetch)];
refreshResult = _d.sent();
if (!(refreshResult.result !== "RETRY")) return [3 /*break*/, 18];
if (!refreshResult.error) return [3 /*break*/, 15];
return [4 /*yield*/, axiosError_1.createAxiosErrorFromFetchResp(refreshResult.error)];
case 14:
retry = _b.sent();
if (!retry) {
returnObj = response;
return [3 /*break*/, 27];
}
return [3 /*break*/, 21];
_b = _d.sent();
return [3 /*break*/, 17];
case 15:
antiCsrfToken = response.headers["anti-csrf"];
if (!(antiCsrfToken !== undefined)) return [3 /*break*/, 18];
return [4 /*yield*/, fetch_1.getIdRefreshToken(true)];
return [4 /*yield*/, axiosError_1.createAxiosErrorFromAxiosResp(response)];
case 16:
tok = _b.sent();
if (!(tok.status === "EXISTS")) return [3 /*break*/, 18];
return [4 /*yield*/, fetch_1.AntiCsrfToken.setItem(tok.token, antiCsrfToken)];
_b = _d.sent();
_d.label = 17;
case 17:
_b.sent();
_b.label = 18;
// Returning refreshResult.error as an Axios Error if we attempted a refresh
// Returning the response to the original response as an error if we did not attempt refreshing
returnObj = _b;
return [3 /*break*/, 35];
case 18:
frontToken = response.headers["front-token"];
if (!(frontToken !== undefined)) return [3 /*break*/, 20];
return [4 /*yield*/, fetch_1.FrontToken.setItem(frontToken)];
return [3 /*break*/, 25];
case 19:
_b.sent();
_b.label = 20;
antiCsrfToken = response.headers["anti-csrf"];
if (!(antiCsrfToken !== undefined)) return [3 /*break*/, 22];
return [4 /*yield*/, fetch_1.getIdRefreshToken(true)];
case 20:
return [2 /*return*/, response];
tok = _d.sent();
if (!(tok.status === "EXISTS")) return [3 /*break*/, 22];
return [4 /*yield*/, fetch_1.AntiCsrfToken.setItem(tok.token, antiCsrfToken)];
case 21:
return [3 /*break*/, 26];
_d.sent();
_d.label = 22;
case 22:
err_1 = _b.sent();
frontToken = response.headers["front-token"];
if (!(frontToken !== undefined)) return [3 /*break*/, 24];
return [4 /*yield*/, fetch_1.FrontToken.setItem(frontToken)];
case 23:
_d.sent();
_d.label = 24;
case 24:
return [2 /*return*/, response];
case 25:
return [3 /*break*/, 34];
case 26:
err_1 = _d.sent();
if (

@@ -618,40 +578,46 @@ !(

)
return [3 /*break*/, 24];
return [4 /*yield*/, fetch_1.handleUnauthorised(preRequestIdToken, axiosFetch)];
case 23:
retry = _b.sent();
if (!retry) {
throwError = true;
returnObj = err_1;
return [3 /*break*/, 27];
}
return [3 /*break*/, 25];
case 24:
throw err_1;
case 25:
return [3 /*break*/, 26];
case 26:
return [3 /*break*/, 4];
return [3 /*break*/, 32];
return [4 /*yield*/, fetch_1.onUnauthorisedResponse(preRequestIdToken)];
case 27:
// if it comes here, means we called break. which happens only if we have logged out.
if (throwError) {
throw returnObj;
} else {
return [2 /*return*/, returnObj];
}
return [3 /*break*/, 33];
refreshResult = _d.sent();
if (!(refreshResult.result !== "RETRY")) return [3 /*break*/, 31];
if (!(refreshResult.error !== undefined)) return [3 /*break*/, 29];
return [4 /*yield*/, axiosError_1.createAxiosErrorFromFetchResp(refreshResult.error)];
case 28:
return [4 /*yield*/, fetch_1.default.recipeImpl.doesSessionExist(fetch_1.default.config)];
_c = _d.sent();
return [3 /*break*/, 30];
case 29:
if (!!_b.sent()) return [3 /*break*/, 32];
return [4 /*yield*/, fetch_1.AntiCsrfToken.removeToken()];
_c = err_1;
_d.label = 30;
case 30:
_b.sent();
return [4 /*yield*/, fetch_1.FrontToken.removeToken()];
// Returning refreshResult.error as an Axios Error if we attempted a refresh
// Returning the original error if we did not attempt refreshing
returnObj = _c;
return [3 /*break*/, 35];
case 31:
_b.sent();
_b.label = 32;
return [3 /*break*/, 33];
case 32:
throw err_1;
case 33:
return [3 /*break*/, 34];
case 34:
return [3 /*break*/, 3];
case 35:
// if it comes here, means we called break. which happens only if we have logged out.
// which means it's a 401, so we throw
throw returnObj;
case 36:
return [4 /*yield*/, fetch_1.default.recipeImpl.doesSessionExist(fetch_1.default.config)];
case 37:
if (!!_d.sent()) return [3 /*break*/, 40];
return [4 /*yield*/, fetch_1.AntiCsrfToken.removeToken()];
case 38:
_d.sent();
return [4 /*yield*/, fetch_1.FrontToken.removeToken()];
case 39:
_d.sent();
_d.label = 40;
case 40:
return [7 /*endfinally*/];
case 33:
case 41:
return [2 /*return*/];

@@ -658,0 +624,0 @@ }

@@ -21,6 +21,2 @@ import { InputType, RecipeInterface, NormalisedInputType } from "./types";

/**
* @description returns true if retry, else false is session has expired completely.
*/
export declare function handleUnauthorised(preRequestIdToken: IdRefreshTokenType, httpCall?: (url: string, init?: RequestInit) => Promise<Response>): Promise<boolean>;
/**
* @class AuthHttpRequest

@@ -45,4 +41,5 @@ * @description wrapper for common http methods.

*/
export declare function onUnauthorisedResponse(preRequestIdToken: IdRefreshTokenType, httpCall?: (url: string, init?: RequestInit) => Promise<Response>): Promise<{
export declare function onUnauthorisedResponse(preRequestIdToken: IdRefreshTokenType): Promise<{
result: "SESSION_EXPIRED";
error?: any;
} | {

@@ -49,0 +46,0 @@ result: "API_ERROR";

@@ -320,25 +320,2 @@ "use strict";

/**
* @description returns true if retry, else false is session has expired completely.
*/
function handleUnauthorised(preRequestIdToken, httpCall) {
return __awaiter(this, void 0, void 0, function() {
var result;
return __generator(this, function(_a) {
switch (_a.label) {
case 0:
return [4 /*yield*/, onUnauthorisedResponse(preRequestIdToken, httpCall)];
case 1:
result = _a.sent();
if (result.result === "SESSION_EXPIRED") {
return [2 /*return*/, false];
} else if (result.result === "API_ERROR") {
throw result.error;
}
return [2 /*return*/, true];
}
});
});
}
exports.handleUnauthorised = handleUnauthorised;
/**
* @class AuthHttpRequest

@@ -377,3 +354,2 @@ * @description wrapper for common http methods.

var doNotDoInterception,
throwError,
returnObj,

@@ -388,5 +364,3 @@ preRequestIdToken,

tok,
frontToken,
err_1,
retry;
frontToken;
return __generator(this, function(_a) {

@@ -436,8 +410,7 @@ switch (_a.label) {

case 3:
_a.trys.push([3, , 26, 31]);
throwError = false;
_a.trys.push([3, , 20, 25]);
returnObj = undefined;
_a.label = 4;
case 4:
if (!true) return [3 /*break*/, 25];
if (!true) return [3 /*break*/, 19];
return [4 /*yield*/, getIdRefreshToken(true)];

@@ -481,88 +454,61 @@ case 5:

});
_a.label = 8;
return [4 /*yield*/, httpCall(configWithAntiCsrf)];
case 8:
_a.trys.push([8, 20, , 24]);
return [4 /*yield*/, httpCall(configWithAntiCsrf)];
case 9:
response = _a.sent();
idRefreshToken = response.headers.get("id-refresh-token");
if (!idRefreshToken) return [3 /*break*/, 11];
if (!idRefreshToken) return [3 /*break*/, 10];
return [4 /*yield*/, setIdRefreshToken(idRefreshToken, response.status)];
case 9:
_a.sent();
_a.label = 10;
case 10:
_a.sent();
_a.label = 11;
if (!(response.status === AuthHttpRequest.config.sessionExpiredStatusCode))
return [3 /*break*/, 12];
return [4 /*yield*/, onUnauthorisedResponse(preRequestIdToken)];
case 11:
if (!(response.status === AuthHttpRequest.config.sessionExpiredStatusCode))
return [3 /*break*/, 13];
return [4 /*yield*/, handleUnauthorised(preRequestIdToken)];
case 12:
retry = _a.sent();
if (!retry) {
returnObj = response;
return [3 /*break*/, 25];
if (retry.result !== "RETRY") {
returnObj = retry.error !== undefined ? retry.error : response;
return [3 /*break*/, 19];
}
return [3 /*break*/, 19];
case 13:
return [3 /*break*/, 18];
case 12:
antiCsrfToken = response.headers.get("anti-csrf");
if (!antiCsrfToken) return [3 /*break*/, 16];
if (!antiCsrfToken) return [3 /*break*/, 15];
return [4 /*yield*/, getIdRefreshToken(true)];
case 14:
case 13:
tok = _a.sent();
if (!(tok.status === "EXISTS")) return [3 /*break*/, 16];
if (!(tok.status === "EXISTS")) return [3 /*break*/, 15];
return [4 /*yield*/, AntiCsrfToken.setItem(tok.token, antiCsrfToken)];
case 14:
_a.sent();
_a.label = 15;
case 15:
_a.sent();
_a.label = 16;
case 16:
frontToken = response.headers.get("front-token");
if (!frontToken) return [3 /*break*/, 18];
if (!frontToken) return [3 /*break*/, 17];
return [4 /*yield*/, FrontToken.setItem(frontToken)];
case 16:
_a.sent();
_a.label = 17;
case 17:
_a.sent();
_a.label = 18;
return [2 /*return*/, response];
case 18:
return [2 /*return*/, response];
return [3 /*break*/, 4];
case 19:
return [3 /*break*/, 24];
// if it comes here, means we breaked. which happens only if we have logged out.
return [2 /*return*/, returnObj];
case 20:
err_1 = _a.sent();
if (!(err_1.status === AuthHttpRequest.config.sessionExpiredStatusCode))
return [3 /*break*/, 22];
return [4 /*yield*/, handleUnauthorised(preRequestIdToken)];
return [4 /*yield*/, AuthHttpRequest.recipeImpl.doesSessionExist(AuthHttpRequest.config)];
case 21:
retry = _a.sent();
if (!retry) {
throwError = true;
returnObj = err_1;
return [3 /*break*/, 25];
}
return [3 /*break*/, 23];
if (!!_a.sent()) return [3 /*break*/, 24];
return [4 /*yield*/, AntiCsrfToken.removeToken()];
case 22:
throw err_1;
case 23:
return [3 /*break*/, 24];
case 24:
return [3 /*break*/, 4];
case 25:
// if it comes here, means we breaked. which happens only if we have logged out.
if (throwError) {
throw returnObj;
} else {
return [2 /*return*/, returnObj];
}
return [3 /*break*/, 31];
case 26:
return [4 /*yield*/, AuthHttpRequest.recipeImpl.doesSessionExist(AuthHttpRequest.config)];
case 27:
if (!!_a.sent()) return [3 /*break*/, 30];
return [4 /*yield*/, AntiCsrfToken.removeToken()];
case 28:
_a.sent();
return [4 /*yield*/, FrontToken.removeToken()];
case 29:
case 23:
_a.sent();
_a.label = 30;
case 30:
_a.label = 24;
case 24:
return [7 /*endfinally*/];
case 31:
case 25:
return [2 /*return*/];

@@ -575,3 +521,3 @@ }

return __awaiter(_this, void 0, void 0, function() {
var preRequestIdToken;
var preRequestIdToken, refresh;
return __generator(this, function(_a) {

@@ -583,5 +529,9 @@ switch (_a.label) {

preRequestIdToken = _a.sent();
return [4 /*yield*/, handleUnauthorised(preRequestIdToken)];
return [4 /*yield*/, onUnauthorisedResponse(preRequestIdToken)];
case 2:
return [2 /*return*/, _a.sent()];
refresh = _a.sent();
if (refresh.result === "API_ERROR") {
throw refresh.error;
}
return [2 /*return*/, refresh.result === "RETRY"];
}

@@ -601,3 +551,3 @@ });

*/
function onUnauthorisedResponse(preRequestIdToken, httpCall) {
function onUnauthorisedResponse(preRequestIdToken) {
return __awaiter(this, void 0, void 0, function() {

@@ -609,3 +559,2 @@ var lock,

preAPIResult,
makeRequest,
response,

@@ -680,4 +629,6 @@ removeIdRefreshToken,

preAPIResult = _a.sent();
makeRequest = httpCall || AuthHttpRequest.env.__supertokensOriginalFetch;
return [4 /*yield*/, makeRequest(preAPIResult.url, preAPIResult.requestInit)];
return [
4 /*yield*/,
AuthHttpRequest.env.__supertokensOriginalFetch(preAPIResult.url, preAPIResult.requestInit)
];
case 8:

@@ -748,3 +699,3 @@ response = _a.sent();

// in the first place.
return [2 /*return*/, { result: "SESSION_EXPIRED" }];
return [2 /*return*/, { result: "SESSION_EXPIRED", error: error_1 }];
}

@@ -823,3 +774,3 @@ return [2 /*return*/, { result: "API_ERROR", error: error_1 }];

}
var token, response, err_2;
var token, response, res;
return __generator(this, function(_a) {

@@ -839,30 +790,25 @@ switch (_a.label) {

}
if (!(token === undefined)) return [3 /*break*/, 8];
if (!(token === undefined)) return [3 /*break*/, 5];
response = {
status: "MAY_EXIST"
};
if (!tryRefresh) return [3 /*break*/, 7];
_a.label = 2;
if (!tryRefresh) return [3 /*break*/, 4];
return [4 /*yield*/, onUnauthorisedResponse(response)];
case 2:
_a.trys.push([2, 4, , 5]);
return [4 /*yield*/, handleUnauthorised(response)];
res = _a.sent();
if (res.result !== "RETRY") {
// in case the backend is not working, we treat it as the session not existing...
return [
2 /*return*/,
{
status: "NOT_EXISTS"
}
];
}
return [4 /*yield*/, getIdRefreshToken(tryRefresh)];
case 3:
_a.sent();
return [3 /*break*/, 5];
return [2 /*return*/, _a.sent()];
case 4:
err_2 = _a.sent();
// in case the backend is not working, we treat it as the session not existing...
return [
2 /*return*/,
{
status: "NOT_EXISTS"
}
];
return [2 /*return*/, response];
case 5:
return [4 /*yield*/, getIdRefreshToken(tryRefresh)];
case 6:
return [2 /*return*/, _a.sent()];
case 7:
return [2 /*return*/, response];
case 8:
return [

@@ -869,0 +815,0 @@ 2 /*return*/,

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

export declare const package_version = "9.0.1";
export declare const package_version = "9.0.2";
export declare const supported_fdi: string[];

@@ -17,3 +17,3 @@ "use strict";

*/
exports.package_version = "9.0.1";
exports.package_version = "9.0.2";
exports.supported_fdi = ["1.8", "1.9"];
{
"name": "supertokens-website",
"version": "9.0.1",
"version": "9.0.2",
"description": "frontend sdk for website to be used for auth solution.",
"main": "index.js",
"dependencies": {
"browser-tabs-lock": "^1.2.14",
"axios": "*"
"browser-tabs-lock": "^1.2.14"
},

@@ -14,2 +13,3 @@ "devDependencies": {

"@babel/preset-env": "^7.15.6",
"axios": "*",
"isomorphic-fetch": "2.2.1",

@@ -60,2 +60,2 @@ "mocha": "6.1.4",

"homepage": "https://github.com/supertokens/supertokens-website#readme"
}
}
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