Comparing version 3.0.1 to 3.0.2
import { StorageType } from './StorageType'; | ||
export declare const applyStorage: (storage: StorageType) => void; | ||
export declare const applyStorage: (storage?: StorageType) => void; | ||
//# sourceMappingURL=applyStorage.d.ts.map |
@@ -6,5 +6,7 @@ "use strict"; | ||
var applyStorage = function (storage) { | ||
StorageProxy_1.StorageProxy.Storage = storage; | ||
if (storage) { | ||
StorageProxy_1.StorageProxy.Storage = storage; | ||
} | ||
}; | ||
exports.applyStorage = applyStorage; | ||
//# sourceMappingURL=applyStorage.js.map |
@@ -1,2 +0,1 @@ | ||
import type { AxiosRequestConfig } from 'axios'; | ||
import { IAuthTokenInterceptorConfig } from './IAuthTokenInterceptorConfig'; | ||
@@ -25,3 +24,3 @@ import { TokenRefreshRequest } from './TokenRefreshRequest'; | ||
*/ | ||
export declare const authTokenInterceptor: ({ header, headerPrefix, requestRefresh, tokenExpireFudge, getStorage, }: IAuthTokenInterceptorConfig) => (requestConfig: AxiosRequestConfig) => Promise<AxiosRequestConfig>; | ||
export declare const authTokenInterceptor: ({ header, headerPrefix, requestRefresh, tokenExpireFudge, getStorage, }: IAuthTokenInterceptorConfig) => (requestConfig: any) => Promise<any>; | ||
//# sourceMappingURL=authTokenInterceptor.d.ts.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -213,2 +213,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
(0, applyStorage_1.applyStorage)(getStorage()); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Waiting for a fix in axios types | ||
return function (requestConfig) { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -219,2 +220,3 @@ var accessToken, error_2; | ||
case 0: | ||
// Waiting for a fix in axios types | ||
// We need refresh token to do any authenticated requests | ||
@@ -221,0 +223,0 @@ if (!(0, tokensUtils_1.getRefreshToken)()) |
import { BrowserStorageService } from './BrowserStorageService'; | ||
export declare const getBrowserLocalStorage: () => BrowserStorageService; | ||
export declare const getBrowserLocalStorage: () => BrowserStorageService | undefined; | ||
//# sourceMappingURL=getBrowserLocalStorage.d.ts.map |
@@ -5,4 +5,8 @@ "use strict"; | ||
var BrowserStorageService_1 = require("./BrowserStorageService"); | ||
var getBrowserLocalStorage = function () { return new BrowserStorageService_1.BrowserStorageService(window.localStorage); }; | ||
var getBrowserLocalStorage = function () { | ||
if (typeof window !== 'undefined') { | ||
return new BrowserStorageService_1.BrowserStorageService(window.localStorage); | ||
} | ||
}; | ||
exports.getBrowserLocalStorage = getBrowserLocalStorage; | ||
//# sourceMappingURL=getBrowserLocalStorage.js.map |
import { BrowserStorageService } from './BrowserStorageService'; | ||
export declare const getBrowserSessionStorage: () => BrowserStorageService; | ||
export declare const getBrowserSessionStorage: () => BrowserStorageService | undefined; | ||
//# sourceMappingURL=getBrowserSessionStorage.d.ts.map |
@@ -5,4 +5,8 @@ "use strict"; | ||
var BrowserStorageService_1 = require("./BrowserStorageService"); | ||
var getBrowserSessionStorage = function () { return new BrowserStorageService_1.BrowserStorageService(window.sessionStorage); }; | ||
var getBrowserSessionStorage = function () { | ||
if (typeof window !== 'undefined') { | ||
return new BrowserStorageService_1.BrowserStorageService(window.sessionStorage); | ||
} | ||
}; | ||
exports.getBrowserSessionStorage = getBrowserSessionStorage; | ||
//# sourceMappingURL=getBrowserSessionStorage.js.map |
@@ -0,4 +1,4 @@ | ||
import { StringValue } from 'ms'; | ||
import { StorageType } from './StorageType'; | ||
import { TokenRefreshRequest } from './TokenRefreshRequest'; | ||
import { StorageType } from './StorageType'; | ||
import { StringValue } from 'ms'; | ||
export interface IAuthTokenInterceptorConfig { | ||
@@ -13,4 +13,4 @@ header?: string; | ||
tokenExpireFudge?: number | StringValue; | ||
getStorage?: () => StorageType; | ||
getStorage?: () => StorageType | undefined; | ||
} | ||
//# sourceMappingURL=IAuthTokenInterceptorConfig.d.ts.map |
import { StorageType } from './StorageType'; | ||
declare type StorageProxyType = { | ||
type StorageProxyType = { | ||
Storage: StorageType | null; | ||
@@ -4,0 +4,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
export declare type StorageType = { | ||
export type StorageType = { | ||
remove(key: string): void; | ||
@@ -3,0 +3,0 @@ set(key: string, value: string): void; |
@@ -1,2 +0,2 @@ | ||
export declare type Token = string; | ||
export type Token = string; | ||
//# sourceMappingURL=Token.d.ts.map |
import { Token } from './Token'; | ||
import { IAuthTokens } from './IAuthTokens'; | ||
export declare type TokenRefreshRequest = (refreshToken: Token) => Promise<Token | IAuthTokens>; | ||
export type TokenRefreshRequest = (refreshToken: Token) => Promise<Token | IAuthTokens>; | ||
//# sourceMappingURL=TokenRefreshRequest.d.ts.map |
{ | ||
"name": "axios-jwt", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Axios interceptor to store, use, and refresh tokens for authentication.", | ||
@@ -15,20 +15,19 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@react-native-async-storage/async-storage": "^1.17.10", | ||
"@types/axios": "0.14.0", | ||
"@types/jest": "29.2.2", | ||
"@types/jsonwebtoken": "8.5.9", | ||
"@react-native-async-storage/async-storage": "1.18.1", | ||
"@types/jest": "29.5.1", | ||
"@types/jsonwebtoken": "9.0.2", | ||
"@types/jwt-decode": "3.1.0", | ||
"@typescript-eslint/eslint-plugin": "5.42.0", | ||
"@typescript-eslint/parser": "5.42.0", | ||
"eslint": "8.27.0", | ||
"jest": "29.2.2", | ||
"jest-environment-jsdom": "29.2.2", | ||
"@typescript-eslint/eslint-plugin": "5.59.1", | ||
"@typescript-eslint/parser": "5.59.1", | ||
"eslint": "8.39.0", | ||
"jest": "29.5.0", | ||
"jest-environment-jsdom": "29.5.0", | ||
"jsonwebtoken": "9.0.0", | ||
"prettier": "2.7.1", | ||
"ts-jest": "29.0.3", | ||
"typescript": "4.8.4" | ||
"prettier": "2.8.8", | ||
"ts-jest": "29.1.0", | ||
"typescript": "5.0.4" | ||
}, | ||
"peerDependencies": { | ||
"@react-native-async-storage/async-storage": "1.15.17", | ||
"axios": "^1.1.3 || ^0.27.0" | ||
"axios": "^1.4.0" | ||
}, | ||
@@ -35,0 +34,0 @@ "peerDependenciesMeta": { |
import { StorageProxy } from './StorageProxy' | ||
import { StorageType } from './StorageType' | ||
export const applyStorage = (storage: StorageType) => { | ||
StorageProxy.Storage = storage | ||
export const applyStorage = (storage?: StorageType) => { | ||
if (storage) { | ||
StorageProxy.Storage = storage | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
import type { AxiosRequestConfig } from 'axios' | ||
import { getAccessToken, getRefreshToken, setAccessToken } from './tokensUtils' | ||
@@ -182,3 +181,5 @@ import { setAuthTokens } from './setAuthTokens' | ||
return async (requestConfig: AxiosRequestConfig): Promise<AxiosRequestConfig> => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Waiting for a fix in axios types | ||
return async (requestConfig: any): Promise<any> => { | ||
// Waiting for a fix in axios types | ||
// We need refresh token to do any authenticated requests | ||
@@ -185,0 +186,0 @@ if (!getRefreshToken()) return requestConfig |
import { BrowserStorageService } from './BrowserStorageService' | ||
export const getBrowserLocalStorage = () => new BrowserStorageService(window.localStorage) | ||
export const getBrowserLocalStorage = () => { | ||
if (typeof window !== 'undefined') { | ||
return new BrowserStorageService(window.localStorage) | ||
} | ||
} |
import { BrowserStorageService } from './BrowserStorageService' | ||
export const getBrowserSessionStorage = () => new BrowserStorageService(window.sessionStorage) | ||
export const getBrowserSessionStorage = () => { | ||
if (typeof window !== 'undefined') { | ||
return new BrowserStorageService(window.sessionStorage) | ||
} | ||
} |
@@ -0,4 +1,4 @@ | ||
import { StringValue } from 'ms' | ||
import { StorageType } from './StorageType' | ||
import { TokenRefreshRequest } from './TokenRefreshRequest' | ||
import { StorageType } from './StorageType' | ||
import { StringValue } from 'ms' | ||
@@ -14,3 +14,3 @@ export interface IAuthTokenInterceptorConfig { | ||
tokenExpireFudge?: number | StringValue | ||
getStorage?: () => StorageType | ||
getStorage?: () => StorageType | undefined | ||
} |
@@ -1,5 +0,6 @@ | ||
import { refreshTokenIfNeeded } from '../index'; | ||
import jwt from 'jsonwebtoken'; | ||
import { refreshTokenIfNeeded } from '../index' | ||
import jwt from 'jsonwebtoken' | ||
import { AxiosError } from 'axios' | ||
import { STORAGE_KEY } from '../src/StorageKey'; | ||
import type { AxiosHeaders } from 'axios' | ||
import { STORAGE_KEY } from '../src/StorageKey' | ||
@@ -10,8 +11,12 @@ function makeAxiosErrorWithStatusCode(statusCode: number) { | ||
'ECONNABORTED', | ||
{ | ||
headers: {} as AxiosHeaders, | ||
}, | ||
{}, | ||
{}, | ||
{ | ||
status: statusCode, | ||
data: {}, | ||
config: {}, | ||
config: { | ||
headers: {} as AxiosHeaders, | ||
}, | ||
headers: {}, | ||
@@ -55,3 +60,5 @@ statusText: '', | ||
// I expect the error handler to have been called with the right error | ||
expect(catchFn).toHaveBeenLastCalledWith(new Error('Failed to refresh auth token: Server error')) | ||
expect(catchFn).toHaveBeenLastCalledWith( | ||
new Error('Failed to refresh auth token: Server error') | ||
) | ||
}) | ||
@@ -90,3 +97,5 @@ | ||
// I expect the error handler to have been called with the right error | ||
expect(catchFn).toHaveBeenLastCalledWith(new Error('Got 401 on token refresh; clearing both auth tokens')) | ||
expect(catchFn).toHaveBeenLastCalledWith( | ||
new Error('Got 401 on token refresh; clearing both auth tokens') | ||
) | ||
// and the storage to have been cleared | ||
@@ -127,3 +136,5 @@ expect(localStorage.getItem(STORAGE_KEY)).toBeNull() | ||
// I expect the error handler to have been called with the right error | ||
expect(catchFn).toHaveBeenLastCalledWith(new Error('Got 422 on token refresh; clearing both auth tokens')) | ||
expect(catchFn).toHaveBeenLastCalledWith( | ||
new Error('Got 422 on token refresh; clearing both auth tokens') | ||
) | ||
// and the storage to have been cleared | ||
@@ -157,3 +168,6 @@ expect(localStorage.getItem(STORAGE_KEY)).toBeNull() | ||
const storedTokens = localStorage.getItem(STORAGE_KEY) as string | ||
expect(JSON.parse(storedTokens)).toEqual({ accessToken: 'newaccesstoken', refreshToken: 'refreshtoken' }) | ||
expect(JSON.parse(storedTokens)).toEqual({ | ||
accessToken: 'newaccesstoken', | ||
refreshToken: 'refreshtoken', | ||
}) | ||
@@ -189,3 +203,6 @@ // and the result to be the new access token | ||
const storedTokens = localStorage.getItem(STORAGE_KEY) as string | ||
expect(JSON.parse(storedTokens)).toEqual({ accessToken: 'newaccesstoken', refreshToken: 'refreshtoken' }) | ||
expect(JSON.parse(storedTokens)).toEqual({ | ||
accessToken: 'newaccesstoken', | ||
refreshToken: 'refreshtoken', | ||
}) | ||
@@ -212,3 +229,6 @@ // and the result to be the new access token | ||
// and I have a requestRefresh function that returns both tokens | ||
const requestRefresh = async () => ({ accessToken: 'newaccesstoken', refreshToken: 'newrefreshtoken' }) | ||
const requestRefresh = async () => ({ | ||
accessToken: 'newaccesstoken', | ||
refreshToken: 'newrefreshtoken', | ||
}) | ||
@@ -222,3 +242,6 @@ // WHEN | ||
const storedTokens = localStorage.getItem(STORAGE_KEY) as string | ||
expect(JSON.parse(storedTokens)).toEqual({ accessToken: 'newaccesstoken', refreshToken: 'newrefreshtoken' }) | ||
expect(JSON.parse(storedTokens)).toEqual({ | ||
accessToken: 'newaccesstoken', | ||
refreshToken: 'newrefreshtoken', | ||
}) | ||
@@ -245,3 +268,6 @@ // and the result to be the new access token | ||
// and I have a requestRefresh function that returns an access token | ||
const requestRefresh = async () => ({ access_token: 'wrongkey!', refresh_token: 'anotherwrongkey!' }) | ||
const requestRefresh = async () => ({ | ||
access_token: 'wrongkey!', | ||
refresh_token: 'anotherwrongkey!', | ||
}) | ||
@@ -248,0 +274,0 @@ // and I have an error handler |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13
92795
107
1729