UNPKG

@spartacus/checkout

Version:

Checkout feature library for Spartacus

533 lines (514 loc) 24.7 kB
import * as i0 from '@angular/core'; import { Injectable, NgModule } from '@angular/core'; import * as i1$1 from '@angular/router'; import { RouterModule } from '@angular/router'; import * as i1 from '@spartacus/core'; import { Config, facadeFactory, provideDefaultConfig, provideDefaultConfigFactory, CxEvent } from '@spartacus/core'; import { OrderEntriesSource, CmsPageGuard, PageLayoutComponent, ORDER_ENTRIES_CONTEXT } from '@spartacus/storefront'; import { HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http'; import { throwError } from 'rxjs'; import { take, switchMap, catchError, map } from 'rxjs/operators'; var CheckoutStepType; (function (CheckoutStepType) { CheckoutStepType["SHIPPING_ADDRESS"] = "shippingAddress"; CheckoutStepType["DELIVERY_MODE"] = "deliveryMode"; CheckoutStepType["PAYMENT_DETAILS"] = "paymentDetails"; CheckoutStepType["REVIEW_ORDER"] = "reviewOrder"; CheckoutStepType["PAYMENT_TYPE"] = "paymentType"; })(CheckoutStepType || (CheckoutStepType = {})); const checkoutShippingSteps = [ CheckoutStepType.SHIPPING_ADDRESS, CheckoutStepType.DELIVERY_MODE, ]; const checkoutPaymentSteps = [ CheckoutStepType.PAYMENT_DETAILS, CheckoutStepType.PAYMENT_TYPE, CheckoutStepType.SHIPPING_ADDRESS, ]; var DeliveryModePreferences; (function (DeliveryModePreferences) { DeliveryModePreferences["FREE"] = "FREE"; DeliveryModePreferences["LEAST_EXPENSIVE"] = "LEAST_EXPENSIVE"; DeliveryModePreferences["MOST_EXPENSIVE"] = "MOST_EXPENSIVE"; })(DeliveryModePreferences || (DeliveryModePreferences = {})); class CheckoutConfig { } CheckoutConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutConfig, providedIn: 'root', useExisting: Config }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutConfig, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useExisting: Config, }] }] }); const defaultCheckoutConfig = { checkout: { steps: [ { id: 'shippingAddress', name: 'checkoutProgress.shippingAddress', routeName: 'checkoutShippingAddress', type: [CheckoutStepType.SHIPPING_ADDRESS], }, { id: 'deliveryMode', name: 'checkoutProgress.deliveryMode', routeName: 'checkoutDeliveryMode', type: [CheckoutStepType.DELIVERY_MODE], }, { id: 'paymentDetails', name: 'checkoutProgress.paymentDetails', routeName: 'checkoutPaymentDetails', type: [CheckoutStepType.PAYMENT_DETAILS], }, { id: 'reviewOrder', name: 'checkoutProgress.reviewOrder', routeName: 'checkoutReviewOrder', type: [CheckoutStepType.REVIEW_ORDER], }, ], express: false, defaultDeliveryMode: [DeliveryModePreferences.FREE], guest: false, }, }; const defaultCheckoutRoutingConfig = { routing: { routes: { checkoutLogin: { paths: ['checkout-login'], authFlow: true }, checkout: { paths: ['checkout'] }, checkoutPaymentType: { paths: ['checkout/payment-type'] }, checkoutShippingAddress: { paths: ['checkout/shipping-address'] }, checkoutDeliveryMode: { paths: ['checkout/delivery-mode'] }, checkoutPaymentDetails: { paths: ['checkout/payment-details'] }, checkoutReviewOrder: { paths: ['checkout/review-order'] }, orderConfirmation: { paths: ['order-confirmation'] }, replenishmentConfirmation: { paths: ['replenishment/confirmation'] }, }, }, }; const CHECKOUT_FEATURE = 'checkout'; const CHECKOUT_CORE_FEATURE = 'checkoutCore'; /** * Interceptor that handles "Cart not found" errors while a user is in a checkout step. * * When a user doing a checkout has a "Cart not found" error, he is redirected to checkout and the cart is reloaded. * If a "Cart not found" error happens and the user is not on checkout, this interceptor does not perform any actions. */ class CheckoutCartInterceptor { constructor(routingService, multiCartService) { this.routingService = routingService; this.multiCartService = multiCartService; } intercept(request, next) { return this.routingService.getRouterState().pipe(take(1), switchMap((state) => { return next.handle(request).pipe(catchError((response) => { var _a; if (response instanceof HttpErrorResponse && this.isUserInCheckoutRoute((_a = state.state) === null || _a === void 0 ? void 0 : _a.semanticRoute)) { if (this.isCartNotFoundError(response)) { this.routingService.go({ cxRoute: 'cart' }); const cartCode = this.getCartIdFromError(response); if (cartCode) { this.multiCartService.reloadCart(cartCode); } } } return throwError(response); })); })); } /** * Returns true if the parameter semantic route is part of "checkout" * Checkout semantic routes: * checkout * checkoutPaymentType * CheckoutShippingAddress * checkoutDeliveryMode * checkoutPaymentDetails * checkoutReviewOrder * checkoutLogin * @param semanticRoute */ isUserInCheckoutRoute(semanticRoute) { var _a; return (_a = semanticRoute === null || semanticRoute === void 0 ? void 0 : semanticRoute.toLowerCase().startsWith('checkout')) !== null && _a !== void 0 ? _a : false; } /** * Checks of the error is for a cart not found, i.e. the cart doesn't exist anymore * * @param response */ isCartNotFoundError(response) { var _a, _b, _c, _d, _e, _f; return (response.status === 400 && ((_c = (_b = (_a = response.error) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.type) === 'CartError' && ((_f = (_e = (_d = response.error) === null || _d === void 0 ? void 0 : _d.errors) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.reason) === 'notFound'); } getCartIdFromError(response) { var _a, _b, _c; return (_c = (_b = (_a = response.error) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.subject; } } CheckoutCartInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutCartInterceptor, deps: [{ token: i1.RoutingService }, { token: i1.MultiCartService }], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutCartInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutCartInterceptor, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutCartInterceptor, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: i1.RoutingService }, { type: i1.MultiCartService }]; } }); const interceptors = [ { provide: HTTP_INTERCEPTORS, useExisting: CheckoutCartInterceptor, multi: true, }, ]; class CheckoutFacade { } CheckoutFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutFacade, providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'placeOrder', 'scheduleReplenishmentOrder', 'getPlaceOrderLoading', 'getPlaceOrderSuccess', 'getPlaceOrderError', 'clearPlaceOrderState', 'clearCheckoutData', 'clearCheckoutStep', 'loadCheckoutDetails', 'getCheckoutDetailsLoaded', 'isLoading', 'getOrderDetails', 'setOrderType', 'getCurrentOrderType', ], async: true, }) }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutFacade, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'placeOrder', 'scheduleReplenishmentOrder', 'getPlaceOrderLoading', 'getPlaceOrderSuccess', 'getPlaceOrderError', 'clearPlaceOrderState', 'clearCheckoutData', 'clearCheckoutStep', 'loadCheckoutDetails', 'getCheckoutDetailsLoaded', 'isLoading', 'getOrderDetails', 'setOrderType', 'getCurrentOrderType', ], async: true, }), }] }] }); class OrderConfirmationOrderEntriesContext { constructor(checkoutService) { this.checkoutService = checkoutService; this.type = OrderEntriesSource.ORDER_CONFIRMATION; } getEntries() { return this.checkoutService .getOrderDetails() .pipe(map((order) => { var _a; return (_a = order === null || order === void 0 ? void 0 : order.entries) !== null && _a !== void 0 ? _a : []; })); } } OrderConfirmationOrderEntriesContext.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: OrderConfirmationOrderEntriesContext, deps: [{ token: CheckoutFacade }], target: i0.ɵɵFactoryTarget.Injectable }); OrderConfirmationOrderEntriesContext.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: OrderConfirmationOrderEntriesContext, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: OrderConfirmationOrderEntriesContext, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: CheckoutFacade }]; } }); function defaultCheckoutComponentsConfig() { const config = { featureModules: { [CHECKOUT_FEATURE]: { cmsComponents: [ 'CheckoutOrchestrator', 'CheckoutOrderSummary', 'CheckoutProgress', 'CheckoutProgressMobileBottom', 'CheckoutProgressMobileTop', 'CheckoutCostCenterComponent', 'CheckoutDeliveryMode', 'CheckoutPaymentDetails', 'CheckoutPaymentType', 'CheckoutPlaceOrder', 'CheckoutReviewOrder', 'CheckoutScheduleReplenishmentOrder', 'CheckoutShippingAddress', 'GuestCheckoutLoginComponent', 'OrderConfirmationThankMessageComponent', 'OrderConfirmationItemsComponent', 'OrderConfirmationTotalsComponent', 'OrderConfirmationOverviewComponent', 'ReplenishmentConfirmationMessageComponent', 'ReplenishmentConfirmationOverviewComponent', 'ReplenishmentConfirmationItemsComponent', 'ReplenishmentConfirmationTotalsComponent', ], }, // by default core is bundled together with components [CHECKOUT_CORE_FEATURE]: CHECKOUT_FEATURE, }, }; return config; } class CheckoutRootModule { } CheckoutRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutRootModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); CheckoutRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutRootModule, imports: [i1$1.RouterModule] }); CheckoutRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutRootModule, providers: [ ...interceptors, provideDefaultConfig(defaultCheckoutRoutingConfig), provideDefaultConfig(defaultCheckoutConfig), provideDefaultConfigFactory(defaultCheckoutComponentsConfig), ], imports: [[ RouterModule.forChild([ { // @ts-ignore path: null, canActivate: [CmsPageGuard], component: PageLayoutComponent, data: { cxRoute: 'orderConfirmation', cxContext: { [ORDER_ENTRIES_CONTEXT]: OrderConfirmationOrderEntriesContext, }, }, }, ]), ]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutRootModule, decorators: [{ type: NgModule, args: [{ imports: [ RouterModule.forChild([ { // @ts-ignore path: null, canActivate: [CmsPageGuard], component: PageLayoutComponent, data: { cxRoute: 'orderConfirmation', cxContext: { [ORDER_ENTRIES_CONTEXT]: OrderConfirmationOrderEntriesContext, }, }, }, ]), ], providers: [ ...interceptors, provideDefaultConfig(defaultCheckoutRoutingConfig), provideDefaultConfig(defaultCheckoutConfig), provideDefaultConfigFactory(defaultCheckoutComponentsConfig), ], }] }] }); /** * Indicates that a user has successfully placed an order */ class OrderPlacedEvent extends CxEvent { } /** * Event's type */ OrderPlacedEvent.type = 'OrderPlacedEvent'; class CheckoutCostCenterFacade { } CheckoutCostCenterFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutCostCenterFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutCostCenterFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutCostCenterFacade, providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutCostCenterFacade, feature: CHECKOUT_CORE_FEATURE, methods: ['setCostCenter', 'getCostCenter'], async: true, }) }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutCostCenterFacade, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutCostCenterFacade, feature: CHECKOUT_CORE_FEATURE, methods: ['setCostCenter', 'getCostCenter'], async: true, }), }] }] }); class CheckoutDeliveryFacade { } CheckoutDeliveryFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutDeliveryFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutDeliveryFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutDeliveryFacade, providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutDeliveryFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'getSupportedDeliveryModes', 'getSelectedDeliveryMode', 'getSelectedDeliveryModeCode', 'getDeliveryAddress', 'getSetDeliveryAddressProcess', 'resetSetDeliveryAddressProcess', 'getSetDeliveryModeProcess', 'resetSetDeliveryModeProcess', 'resetLoadSupportedDeliveryModesProcess', 'getLoadSupportedDeliveryModeProcess', 'clearCheckoutDeliveryModes', 'createAndSetAddress', 'loadSupportedDeliveryModes', 'setDeliveryMode', 'setDeliveryAddress', 'clearCheckoutDeliveryAddress', 'clearCheckoutDeliveryMode', 'clearCheckoutDeliveryDetails', ], async: true, }) }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutDeliveryFacade, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutDeliveryFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'getSupportedDeliveryModes', 'getSelectedDeliveryMode', 'getSelectedDeliveryModeCode', 'getDeliveryAddress', 'getSetDeliveryAddressProcess', 'resetSetDeliveryAddressProcess', 'getSetDeliveryModeProcess', 'resetSetDeliveryModeProcess', 'resetLoadSupportedDeliveryModesProcess', 'getLoadSupportedDeliveryModeProcess', 'clearCheckoutDeliveryModes', 'createAndSetAddress', 'loadSupportedDeliveryModes', 'setDeliveryMode', 'setDeliveryAddress', 'clearCheckoutDeliveryAddress', 'clearCheckoutDeliveryMode', 'clearCheckoutDeliveryDetails', ], async: true, }), }] }] }); class CheckoutPaymentFacade { } CheckoutPaymentFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutPaymentFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutPaymentFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutPaymentFacade, providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutPaymentFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'getCardTypes', 'getPaymentDetails', 'getSetPaymentDetailsResultProcess', 'resetSetPaymentDetailsProcess', 'loadSupportedCardTypes', 'createPaymentDetails', 'setPaymentDetails', 'paymentProcessSuccess', ], async: true, }) }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutPaymentFacade, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useFactory: () => facadeFactory({ facade: CheckoutPaymentFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'getCardTypes', 'getPaymentDetails', 'getSetPaymentDetailsResultProcess', 'resetSetPaymentDetailsProcess', 'loadSupportedCardTypes', 'createPaymentDetails', 'setPaymentDetails', 'paymentProcessSuccess', ], async: true, }), }] }] }); class ClearCheckoutFacade { } ClearCheckoutFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: ClearCheckoutFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); ClearCheckoutFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: ClearCheckoutFacade, providedIn: 'root', useFactory: () => facadeFactory({ facade: ClearCheckoutFacade, feature: CHECKOUT_CORE_FEATURE, methods: ['resetCheckoutProcesses'], async: true, }) }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: ClearCheckoutFacade, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useFactory: () => facadeFactory({ facade: ClearCheckoutFacade, feature: CHECKOUT_CORE_FEATURE, methods: ['resetCheckoutProcesses'], async: true, }), }] }] }); class PaymentTypeFacade { } PaymentTypeFacade.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: PaymentTypeFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); PaymentTypeFacade.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: PaymentTypeFacade, providedIn: 'root', useFactory: () => facadeFactory({ facade: PaymentTypeFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'getPaymentTypes', 'loadPaymentTypes', 'setPaymentType', 'getSelectedPaymentType', 'isAccountPayment', 'getPoNumber', ], async: true, }) }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: PaymentTypeFacade, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useFactory: () => facadeFactory({ facade: PaymentTypeFacade, feature: CHECKOUT_CORE_FEATURE, methods: [ 'getPaymentTypes', 'loadPaymentTypes', 'setPaymentType', 'getSelectedPaymentType', 'isAccountPayment', 'getPoNumber', ], async: true, }), }] }] }); /** * Generated bundle index. Do not edit. */ export { CHECKOUT_CORE_FEATURE, CHECKOUT_FEATURE, CheckoutConfig, CheckoutCostCenterFacade, CheckoutDeliveryFacade, CheckoutFacade, CheckoutPaymentFacade, CheckoutRootModule, CheckoutStepType, ClearCheckoutFacade, DeliveryModePreferences, OrderConfirmationOrderEntriesContext, OrderPlacedEvent, PaymentTypeFacade, checkoutPaymentSteps, checkoutShippingSteps, defaultCheckoutComponentsConfig }; //# sourceMappingURL=spartacus-checkout-root.js.map