-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce optional ICM Compatibility Interceptor (#1542)
* can be used for `messageToMerchant` feature toggle compatibility with ICM 7.10 * see https://github.com/intershop/intershop-pwa/blob/develop/docs/guides/migrations.md#from-50-to-51 Co-authored-by: Stefan Hauke <[email protected]>
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 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
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
31 changes: 31 additions & 0 deletions
31
src/app/core/interceptors/icm-compatibility.interceptor.ts
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,31 @@ | ||
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, map, withLatestFrom } from 'rxjs'; | ||
|
||
import { FeatureToggleService } from 'ish-core/feature-toggle.module'; | ||
|
||
// not-dead-code | ||
/** | ||
* provides a compatibility layer for REST API changes in newer ICM versions | ||
* please enable the interceptor in the `core.module.ts` if needed | ||
* e.g. `messageToMerchant` is no longer an environment feature toggle in ICM 11 but controlled by the configurations call | ||
*/ | ||
@Injectable() | ||
export class ICMCompatibilityInterceptor implements HttpInterceptor { | ||
constructor(private featureToggleService: FeatureToggleService) {} | ||
|
||
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { | ||
if (req.url.endsWith('/configurations') && req instanceof HttpRequest) { | ||
return next.handle(req).pipe( | ||
withLatestFrom(this.featureToggleService.enabled$('messageToMerchant')), | ||
map(([event, messageToMerchant]) => { | ||
if (event instanceof HttpResponse && messageToMerchant && event.body?.data?.shipping) { | ||
event.body.data.shipping.messageToMerchant = true; | ||
} | ||
return event; | ||
}) | ||
); | ||
} | ||
return next.handle(req); | ||
} | ||
} |
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