Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic: CXSPA-2897 #17399

Merged
merged 20 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cf74b84
chore: RxJs 7 (#17362)
ercultimate May 8, 2023
bbdf149
chore: fix compilation errors in libraries
ercultimate May 8, 2023
007cdf1
CXSPA-3077: Cleanup deprecated `retryWhen()` (#17385)
ercultimate May 10, 2023
f2f9366
chore: cleanup deprecated `publishReplay()` (#17387)
ercultimate May 10, 2023
f481daa
chore: Clean up deprecated `BehaviorSubject.hasError` (#17390)
ercultimate May 10, 2023
0599c86
chore: cleanup deprecated `throwError()` (#17386)
ercultimate May 10, 2023
2a7b2b5
chore: Cleanup deprecated `toPromise()` (#17383)
ercultimate May 11, 2023
c78b1fc
Merge remote-tracking branch 'origin/develop-6.1.x' into epic/CXSPA-2897
ercultimate May 11, 2023
866ca82
chore: fix sonar issues
ercultimate May 11, 2023
fa32810
Merge branch 'develop-6.5.x' into epic/CXSPA-2897
pawelfras Sep 27, 2023
fc60129
feat: CXSPA-4804 add missing logger service
pawelfras Sep 27, 2023
2f46c1b
Merge branch 'develop-6.5.x' into epic/CXSPA-2897
pawelfras Sep 27, 2023
9fb5c47
Merge branch 'develop-6.5.x' into epic/CXSPA-2897
pawelfras Oct 3, 2023
33f980c
chore: CXSPA-4841 Fix unit tests and dependencies (#17904)
pawelfras Oct 3, 2023
f538f1a
Trigger Build
pawelfras Oct 4, 2023
035189c
chore: CXSPA-4884 Tap operator handlers (#17905)
pawelfras Oct 5, 2023
a2bfa27
Merge branch 'develop-6.6.x' into epic/CXSPA-2897
pawelfras Oct 5, 2023
eb7351e
Merge branch 'develop-6.6.x' into epic/CXSPA-2897
pawelfras Oct 9, 2023
03191df
Merge branch 'develop-2402.0.x' into epic/CXSPA-2897
kpawelczak Oct 20, 2023
9a6ef32
Merge branch 'develop-next-major' into epic/CXSPA-2897
kpawelczak Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions docs/libs/creating-lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,15 @@ Just copy paste the following and and make sure to rename `TODO:` to you lib's n
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['parallel', 'jasmine', '@angular-devkit/build-angular'],
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-parallel'),
require('karma-jasmine'),
require('karma-coverage'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-junit-reporter'),
],
parallelOptions: {
executors: 2,
shardStrategy: 'round-robin',
},
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
Expand Down Expand Up @@ -220,7 +215,7 @@ Use the following template:
"peerDependencies": {
"@angular/common": "^10.1.0",
"@angular/core": "^10.1.0",
"rxjs": "^6.6.0",
"rxjs": "^7.8.0",
"@spartacus/core": "3.0.0-next.0",
"@spartacus/storefront": "3.0.0-next.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ describe('AsmBindCartComponent', () => {
it('should alert through global messsages when the bind cart fails', () => {
const expectedErrorMessage = 'mock-error-message';
(asmBindCartFacade.bindCart as jasmine.Spy).and.returnValue(
throwError({ details: [{ message: expectedErrorMessage }] })
throwError(() => ({
details: [{ message: expectedErrorMessage }],
}))
);

component.bindCartToCustomer();
Expand Down
7 changes: 1 addition & 6 deletions feature-libs/asm/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['parallel', 'jasmine', '@angular-devkit/build-angular'],
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-parallel'),
require('karma-jasmine'),
require('karma-coverage'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-junit-reporter'),
],
parallelOptions: {
executors: 2,
shardStrategy: 'round-robin',
},
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmine: {
Expand Down
34 changes: 17 additions & 17 deletions feature-libs/asm/occ/adapters/occ-asm.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
User,
normalizeHttpError,
} from '@spartacus/core';
import { Observable, throwError } from 'rxjs';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';

@Injectable()
Expand Down Expand Up @@ -75,7 +75,9 @@ export class OccAsmAdapter implements AsmAdapter {
);

return this.http.get<CustomerListsPage>(url, { headers, params }).pipe(
catchError((error) => throwError(normalizeHttpError(error, this.logger))),
catchError((error) => {
throw normalizeHttpError(error, this.logger);
}),
this.converterService.pipeable(CUSTOMER_LISTS_NORMALIZER)
);
}
Expand Down Expand Up @@ -123,7 +125,9 @@ export class OccAsmAdapter implements AsmAdapter {
);

return this.http.get<CustomerSearchPage>(url, { headers, params }).pipe(
catchError((error) => throwError(normalizeHttpError(error, this.logger))),
catchError((error) => {
throw normalizeHttpError(error, this.logger);
}),
this.converterService.pipeable(CUSTOMER_SEARCH_PAGE_NORMALIZER)
);
}
Expand All @@ -148,13 +152,11 @@ export class OccAsmAdapter implements AsmAdapter {
}
);

return this.http
.post<void>(url, {}, { headers, params })
.pipe(
catchError((error) =>
throwError(normalizeHttpError(error, this.logger))
)
);
return this.http.post<void>(url, {}, { headers, params }).pipe(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
);
}

createCustomer(user: CustomerRegistrationForm): Observable<User> {
Expand All @@ -172,12 +174,10 @@ export class OccAsmAdapter implements AsmAdapter {
prefix: false,
}
);
return this.http
.post<User>(url, user, { headers, params })
.pipe(
catchError((error) =>
throwError(normalizeHttpError(error, this.logger))
)
);
return this.http.post<User>(url, user, { headers, params }).pipe(
catchError((error) => {
throw normalizeHttpError(error, this.logger);
})
);
}
}
2 changes: 1 addition & 1 deletion feature-libs/asm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@spartacus/storefront": "6.6.0-1",
"@spartacus/styles": "6.6.0-1",
"@spartacus/user": "6.6.0-1",
"rxjs": "^6.6.0"
"rxjs": "^7.8.0"
},
"publishConfig": {
"access": "public"
Expand Down
9 changes: 4 additions & 5 deletions feature-libs/asm/root/services/asm-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
StateWithClientAuth,
UserIdService,
} from '@spartacus/core';
import { combineLatest, from, Observable, of } from 'rxjs';
import { combineLatest, from, lastValueFrom, Observable, of } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
import { AsmAuthStorageService, TokenTarget } from './asm-auth-storage.service';

Expand Down Expand Up @@ -109,9 +109,8 @@ export class AsmAuthService extends AuthService {
* To perform logout it is best to use `logout` method. Use this method with caution.
*/
coreLogout(): Promise<any> {
return this.userIdService
.isEmulated()
.pipe(
return lastValueFrom(
this.userIdService.isEmulated().pipe(
take(1),
switchMap((isEmulated) => {
if (isEmulated) {
Expand All @@ -124,7 +123,7 @@ export class AsmAuthService extends AuthService {
}
})
)
.toPromise();
);
}

/**
Expand Down
13 changes: 6 additions & 7 deletions feature-libs/cart/base/core/cart-persistence.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@
*/

import { NgModule } from '@angular/core';
import { Action, ActionReducer, MetaReducer, META_REDUCERS } from '@ngrx/store';
import { Action, ActionReducer, META_REDUCERS, MetaReducer } from '@ngrx/store';
import { CartType } from '@spartacus/cart/base/root';
import {
Config,
ConfigInitializerService,
MODULE_INITIALIZER,
} from '@spartacus/core';
import { lastValueFrom } from 'rxjs';
import { tap } from 'rxjs/operators';
import { MultiCartStatePersistenceService } from './services/multi-cart-state-persistence.service';

export function cartStatePersistenceFactory(
cartStatePersistenceService: MultiCartStatePersistenceService,
configInit: ConfigInitializerService
): () => Promise<Config> {
const result = () =>
configInit
.getStable('context')
.pipe(
return () =>
lastValueFrom(
configInit.getStable('context').pipe(
tap(() => {
cartStatePersistenceService.initSync();
})
)
.toPromise();
return result;
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions feature-libs/cart/base/core/facade/multi-cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
OrderEntry,
} from '@spartacus/cart/base/root';
import { isNotUndefined, StateUtils, UserIdService } from '@spartacus/core';
import { EMPTY, Observable, timer } from 'rxjs';
import { Observable, of, timer } from 'rxjs';
import {
debounce,
distinctUntilChanged,
Expand Down Expand Up @@ -76,7 +76,7 @@ export class MultiCartService implements MultiCartFacade {
// This flickering should only be avoided when switching from false to true
// Start of loading should be showed instantly (no debounce)
// Extra actions are only dispatched after some loading
debounce((isStable) => (isStable ? timer(0) : EMPTY)),
debounce((isStable) => (isStable ? timer(0) : of(undefined))),
distinctUntilChanged()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ describe('Cart Voucher effect', () => {

it('should fail', () => {
const error = new HttpErrorResponse({ error: 'error' });
cartVoucherConnector.add = createSpy().and.returnValue(throwError(error));
cartVoucherConnector.add = createSpy().and.returnValue(
throwError(() => error)
);
const action = new CartActions.CartAddVoucher({
userId,
cartId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ describe('Cart effect', () => {
extraData: { active: true },
});
loadMock.and.returnValue(
throwError({
throwError(() => ({
error: {
errors: [
{ reason: 'notFound', subjectType: 'cart', subject: '123456' },
],
},
})
}))
);
const removeCartCompletion = new CartActions.RemoveCart({ cartId });
actions$ = hot('-a', { a: action });
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Cart effect', () => {
},
});
const action = new CartActions.LoadCart(payload);
loadMock.and.returnValue(throwError(httpError));
loadMock.and.returnValue(throwError(() => httpError));
const removeCartCompletion = new CartActions.LoadCartFail({
...payload,
error: normalizeHttpError(httpError),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
OccEndpointsService,
normalizeHttpError,
} from '@spartacus/core';
import { Observable, throwError } from 'rxjs';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';

@Injectable()
Expand All @@ -36,7 +36,9 @@ export class OccCartValidationAdapter implements CartValidationAdapter {
});

return this.http.post<any>(url, null).pipe(
catchError((error) => throwError(normalizeHttpError(error, this.logger))),
catchError((error) => {
throw normalizeHttpError(error, this.logger);
}),
this.converter.pipeable(CART_VALIDATION_NORMALIZER)
);
}
Expand Down
22 changes: 15 additions & 7 deletions feature-libs/cart/base/occ/adapters/occ-cart-voucher.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
*/

import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { CartVoucherAdapter } from '@spartacus/cart/base/core';
import { CART_VOUCHER_NORMALIZER } from '@spartacus/cart/base/root';
import {
ConverterService,
InterceptorUtil,
OccEndpointsService,
LoggerService,
OCC_USER_ID_ANONYMOUS,
OccEndpointsService,
USE_CLIENT_TOKEN,
normalizeHttpError,
} from '@spartacus/core';
import { Observable, throwError } from 'rxjs';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';

@Injectable()
export class OccCartVoucherAdapter implements CartVoucherAdapter {
protected logger = inject(LoggerService);

constructor(
protected http: HttpClient,
protected occEndpoints: OccEndpointsService,
Expand Down Expand Up @@ -54,7 +58,9 @@ export class OccCartVoucherAdapter implements CartVoucherAdapter {
const headers = this.getHeaders(userId);

return this.http.post(url, toAdd, { headers, params }).pipe(
catchError((error: any) => throwError(error)),
catchError((error: any) => {
throw normalizeHttpError(error, this.logger);
}),
this.converter.pipeable(CART_VOUCHER_NORMALIZER)
);
}
Expand All @@ -67,8 +73,10 @@ export class OccCartVoucherAdapter implements CartVoucherAdapter {

const headers = this.getHeaders(userId);

return this.http
.delete(url, { headers })
.pipe(catchError((error: any) => throwError(error)));
return this.http.delete(url, { headers }).pipe(
catchError((error: any) => {
throw normalizeHttpError(error, this.logger);
})
);
}
}
2 changes: 1 addition & 1 deletion feature-libs/cart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@spartacus/styles": "6.6.0-1",
"@spartacus/user": "6.6.0-1",
"bootstrap": "^4.6.2",
"rxjs": "^6.6.0"
"rxjs": "^7.8.0"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ describe('QuickOrderOrderEntriesContext', () => {
it('should catch unknown identifier error', () => {
canAdd$.next(true);
productConnector.get = createSpy().and.returnValue(
throwError({
throwError(() => ({
error: {
errors: [{ type: 'UnknownIdentifierError' }],
},
})
}))
);

const unableToAddProductsData: ProductData[] = [
Expand Down Expand Up @@ -240,7 +240,9 @@ describe('QuickOrderOrderEntriesContext', () => {

it('should catch unknown errors', () => {
canAdd$.next(true);
productConnector.get = createSpy().and.returnValue(throwError({}));
productConnector.get = createSpy().and.returnValue(
throwError(() => ({}))
);

const unableToAddProductsData: ProductData[] = [
{ productCode: unhandledItemErrorId, quantity: 1 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ describe(`OccCheckoutCostCenterAdapter`, () => {

describe(`back-off`, () => {
it(`should unsuccessfully backOff on Jalo error`, fakeAsync(() => {
spyOn(httpClient, 'put').and.returnValue(throwError(mockJaloError));
spyOn(httpClient, 'put').and.returnValue(
throwError(() => mockJaloError)
);

let result: HttpErrorModel | undefined;
const subscription = service
Expand All @@ -127,7 +129,7 @@ describe(`OccCheckoutCostCenterAdapter`, () => {
if (calledTimes === 3) {
return of(cartData);
}
return throwError(mockJaloError);
return throwError(() => mockJaloError);
})
);

Expand Down
Loading