-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-utils): enable minor config files proxy interception
enables search index and services tiles config interception
- Loading branch information
1 parent
002f2d9
commit 49b7aed
Showing
6 changed files
with
130 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
export function matchNavigationRequest(url: string): boolean { | ||
return !!url.match(/\/api\/chrome-service\/v1\/static\/bundles-generated\.json/); | ||
} | ||
|
||
export function matchSearchIndexRequest(url: string): boolean { | ||
return !!url.match(/\/api\/chrome-service\/v1\/static\/search-index-generated\.json/); | ||
} | ||
|
||
export function matchServiceTilesRequest(url: string): boolean { | ||
return !!url.match(/\/api\/chrome-service\/v1\/static\/service-tiles-generated\.json/); | ||
} | ||
|
||
export function isInterceptAbleRequest(url: string): boolean { | ||
const checks = [matchNavigationRequest, matchSearchIndexRequest, matchServiceTilesRequest]; | ||
return checks.some((check) => check(url)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { matchNavigationRequest, matchSearchIndexRequest, matchServiceTilesRequest } from './check-outgoing-requests'; | ||
import { ChromeStaticSearchEntry, FrontendCRD, GeneratedBundles, ServicesTilesResponseEntry } from './feo-types'; | ||
import navigationInterceptor from './navigation-interceptor'; | ||
import searchInterceptor from './search-interceptor'; | ||
import serviceTilesInterceptor from './service-tiles-interceptor'; | ||
|
||
function isGeneratedBundles( | ||
body: GeneratedBundles | ChromeStaticSearchEntry[] | ServicesTilesResponseEntry[], | ||
url: string | ||
): body is GeneratedBundles { | ||
return matchNavigationRequest(url); | ||
} | ||
|
||
function isSearchIndex( | ||
body: GeneratedBundles | ChromeStaticSearchEntry[] | ServicesTilesResponseEntry[], | ||
url: string | ||
): body is ChromeStaticSearchEntry[] { | ||
return matchSearchIndexRequest(url); | ||
} | ||
|
||
function isServiceTiles( | ||
body: GeneratedBundles | ChromeStaticSearchEntry[] | ServicesTilesResponseEntry[], | ||
url: string | ||
): body is ServicesTilesResponseEntry[] { | ||
return matchServiceTilesRequest(url); | ||
} | ||
|
||
export function modifyRequest(body: string, url: string, frontendCrd: FrontendCRD): string { | ||
const objectToModify = JSON.parse(body); | ||
// return original if no match is found | ||
let payload: string = body; | ||
if (isGeneratedBundles(objectToModify, url)) { | ||
const resultBundles: GeneratedBundles = []; | ||
objectToModify.forEach((bundle) => { | ||
const navItems = navigationInterceptor(frontendCrd, bundle, bundle.id); | ||
resultBundles.push({ ...bundle, navItems }); | ||
}); | ||
payload = JSON.stringify(resultBundles); | ||
} else if (isSearchIndex(objectToModify, url)) { | ||
const staticSearch = objectToModify as ChromeStaticSearchEntry[]; | ||
const result = searchInterceptor(staticSearch, frontendCrd); | ||
payload = JSON.stringify(result); | ||
} else if (isServiceTiles(objectToModify, url)) { | ||
const staticServicesTiles = objectToModify as ServicesTilesResponseEntry[]; | ||
const result = serviceTilesInterceptor(staticServicesTiles, frontendCrd); | ||
payload = JSON.stringify(result); | ||
} | ||
return payload; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters