@adv-ui/ij-axios-interceptor
Advanced tools
Comparing version 1.2.0 to 1.3.0
# CHANGELOG | ||
# 1.3.0 (2023-06-19) | ||
### Features | ||
* **axios-interceptor:** Remove cancelToken deprecated behaviour ([cc7602f](https://github.mpi-internal.com/scmspain/frontend-jobs--common/commit/cc7602fe068dbfe42642088204bd880f37ad38d6)) | ||
# 1.2.0 (2023-06-07) | ||
@@ -4,0 +13,0 @@ |
@@ -1,3 +0,1 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import { CancelToken } from 'axios'; | ||
import { match } from 'node-match-path'; | ||
@@ -9,9 +7,9 @@ var AxiosInterceptor = /*#__PURE__*/function () { | ||
var fetcher = _ref.fetcher, | ||
currentPortal = _ref.currentPortal, | ||
_ref$filterPortalPath = _ref.filterPortalPaths, | ||
filterPortalPaths = _ref$filterPortalPath === void 0 ? [] : _ref$filterPortalPath; | ||
var currentPortalFilter = filterPortalPaths.find(function (filter) { | ||
return currentPortal.includes(filter.portalTLD); | ||
currentTenant = _ref.currentTenant, | ||
_ref$filterTenantPath = _ref.filterTenantPaths, | ||
filterTenantPaths = _ref$filterTenantPath === void 0 ? [] : _ref$filterTenantPath; | ||
var currentTenantFilter = filterTenantPaths.find(function (filter) { | ||
return currentTenant.includes(filter.tenant); | ||
}); | ||
if (!currentPortalFilter) { | ||
if (!currentTenantFilter) { | ||
return; | ||
@@ -21,3 +19,3 @@ } | ||
var url = new URL(req.url); | ||
var allowedPathsList = currentPortalFilter.allowedPathsList; | ||
var allowedPathsList = currentTenantFilter.allowedPathsList; | ||
var isPathAllowed = allowedPathsList.some(function (_ref2) { | ||
@@ -34,8 +32,8 @@ var path = _ref2.path, | ||
} | ||
return _extends({}, req, { | ||
cancelToken: new CancelToken(function (cancel) { | ||
console.log('THE FOLLOWING REQUEST HAS BEEN BLOCKED: ', req); | ||
cancel('Request aborted'); | ||
}) | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('THE FOLLOWING REQUEST HAS BEEN BLOCKED: ', req); | ||
throw new Error('Request aborted'); | ||
}, function (error) { | ||
return Promise.reject(error); | ||
}); | ||
@@ -42,0 +40,0 @@ }; |
{ | ||
"name": "@adv-ui/ij-axios-interceptor", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Axios interceptor", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -11,3 +11,3 @@ ![](https://img.shields.io/badge/automatic-release-brightgreen) | ||
### Intercept request regarding the tenant/portal | ||
### Intercept request regarding the tenant | ||
@@ -24,5 +24,5 @@ The `setBlockingInterceptor` method purpose is to block requests depending on the tenant we provide | ||
const filterPortalPaths = [ | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.net', | ||
tenant: 'infojobs', | ||
whiteListPaths: [{path: '/users', method: 'GET'}, {path: '/user/:id'}] | ||
@@ -36,4 +36,4 @@ } | ||
fetcher, | ||
currentPortal: 'infojobs.net', | ||
filterPortalPaths | ||
currentTenant: 'infojobs', | ||
filterTenantPaths | ||
}) | ||
@@ -40,0 +40,0 @@ ``` |
@@ -34,7 +34,7 @@ import {expect} from 'chai' | ||
describe('should do the request', () => { | ||
it('when the current portal is not in the filterPortalPaths list', async () => { | ||
const currentPortal = '.net' | ||
const filterPortalPaths = [ | ||
it('when the current tenant is not in the filterTenantPaths list', async () => { | ||
const currentTenant = 'infojobs' | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.it', | ||
tenant: 'infojobs_it', | ||
allowedPathsList: [] | ||
@@ -46,4 +46,4 @@ } | ||
fetcher, | ||
currentPortal, | ||
filterPortalPaths | ||
currentTenant, | ||
filterTenantPaths | ||
}) | ||
@@ -58,7 +58,7 @@ | ||
it('when the current portal is in the filterPortalPaths and the path is in the allowedPathsList', async () => { | ||
const currentPortal = '.net' | ||
const filterPortalPaths = [ | ||
it('when the current tenant is in the filterTenantPaths and the path is in the allowedPathsList', async () => { | ||
const currentTenant = 'infojobs' | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.net', | ||
tenant: 'infojobs', | ||
allowedPathsList: [{path: '/test'}] | ||
@@ -70,4 +70,4 @@ } | ||
fetcher, | ||
currentPortal, | ||
filterPortalPaths | ||
currentTenant, | ||
filterTenantPaths | ||
}) | ||
@@ -84,7 +84,7 @@ | ||
describe('should not do the request', () => { | ||
it('when the current portal is in the filterPortalPaths list and do not have any path in the white list', async () => { | ||
const currentPortal = '.net' | ||
const filterPortalPaths = [ | ||
it('when the current tenant is in the filterTenantPaths list and do not have any path in the white list', async () => { | ||
const currentTenant = 'infojobs' | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.net', | ||
tenant: 'infojobs', | ||
allowedPathsList: [] | ||
@@ -96,4 +96,4 @@ } | ||
fetcher, | ||
currentPortal, | ||
filterPortalPaths | ||
currentTenant, | ||
filterTenantPaths | ||
}) | ||
@@ -108,7 +108,7 @@ | ||
it('when the current portal is in the filterPortalPaths list and the path used is not in the white list', async () => { | ||
const currentPortal = '.net' | ||
const filterPortalPaths = [ | ||
it('when the current tenant is in the filterTenantPaths list and the path used is not in the white list', async () => { | ||
const currentTenant = 'infojobs' | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.net', | ||
tenant: 'infojobs', | ||
allowedPathsList: [{path: '/test'}] | ||
@@ -120,4 +120,4 @@ } | ||
fetcher, | ||
currentPortal, | ||
filterPortalPaths | ||
currentTenant, | ||
filterTenantPaths | ||
}) | ||
@@ -132,7 +132,7 @@ | ||
it('when the current portal is in the filterPortalPaths list and the method used is not in the white list', async () => { | ||
const currentPortal = '.net' | ||
const filterPortalPaths = [ | ||
it('when the current tenant is in the filterTenantPaths list and the method used is not in the white list', async () => { | ||
const currentTenant = 'infojobs' | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.net', | ||
tenant: 'infojobs', | ||
allowedPathsList: [{path: '/test', method: 'get'}] | ||
@@ -144,4 +144,4 @@ } | ||
fetcher, | ||
currentPortal, | ||
filterPortalPaths | ||
currentTenant, | ||
filterTenantPaths | ||
}) | ||
@@ -157,7 +157,7 @@ | ||
it('should only allow the requests if the portal is in the filterPortalPaths and the path and the method used are in the white list', async () => { | ||
const currentPortal = '.net' | ||
const filterPortalPaths = [ | ||
it('should only allow the requests if the tenant is in the filterTenantPaths and the path and the method used are in the white list', async () => { | ||
const currentTenant = 'infojobs' | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.net', | ||
tenant: 'infojobs', | ||
allowedPathsList: [ | ||
@@ -172,4 +172,4 @@ {path: '/test', method: 'get'}, | ||
fetcher, | ||
currentPortal, | ||
filterPortalPaths | ||
currentTenant, | ||
filterTenantPaths | ||
}) | ||
@@ -194,7 +194,7 @@ | ||
it('should allow the requests if the portal is in the filterPortalPaths and the path match perfectly in the white list', async () => { | ||
const currentPortal = '.net' | ||
const filterPortalPaths = [ | ||
it('should allow the requests if the tenant is in the filterTenantPaths and the path match perfectly in the white list', async () => { | ||
const currentTenant = 'infojobs' | ||
const filterTenantPaths = [ | ||
{ | ||
portalTLD: '.net', | ||
tenant: 'infojobs', | ||
allowedPathsList: [{path: '/test/:id'}] | ||
@@ -206,4 +206,4 @@ } | ||
fetcher, | ||
currentPortal, | ||
filterPortalPaths | ||
currentTenant, | ||
filterTenantPaths | ||
}) | ||
@@ -210,0 +210,0 @@ |
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
10981
212