New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bloomreach/brx-spartacus-library

Package Overview
Dependencies
Maintainers
29
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bloomreach/brx-spartacus-library

Bloomreach Spartacus Integration Library

  • 1.0.0-beta2
  • Source
  • npm
  • Socket score

Version published
Maintainers
29
Created
Source

Bloomreach Spartacus Library

The Bloomreach Spartacus Library enables SAP Commerce Cloud customers Bloomreach Content (replacing SmartEdit) and Discovery capabilities on top of SAP Commerce Cloud stack. The Bloomreach Spartacus Library interacts with the following:

  • Page Model API
  • Bloomreach Angular SDK
  • Spartacus Storefront
  • Spartacus Core Library
  • Spartacus Assets
  • Spartacus Styles

Components

  • Category highlight
  • Spartacus banner
  • Spartacus product facet navigation
  • Spartacus product carousel
  • Spartacus product details page
  • Spartacus product grid
  • Spartacus searchbox
  • Spartacus search results

Getting Started

  • Build a Spartacus Storefront App by following the instructions here
  • Once done with the previous step proceed with the following:

Installation

To get the SDK into your project with NPM:

npm install @bloomreach/brx-spartacus-library

Or with Yarn:

yarn add @bloomreach/brx-spartacus-library

Usage

The following code snippets render a simple page with a Spartacus banner component:

src/app/app.module.ts

In the NgModule metadata, you'll need to import BrxSpartacusLibModule and provide all the necessary variables in environment variables: see here for the full environment variables configuration documentation.

import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser';
import { EffectsModule } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';
import { BrxSpartacusLibModule } from '@bloomreach/brx-spartacus-library';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrxModule } from './brx/brx.module';
import { SpartacusModule } from './spartacus/spartacus.module';
import { NewsPageComponent } from './pages/news-page/news-page.component';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent,
    NewsPageComponent
  ],
  imports: [
    CommonModule,
    BrowserModule.withServerTransition({ appId: 'serverApp' }),
    HttpClientModule,
    AppRoutingModule,
    StoreModule.forRoot({}),
    EffectsModule.forRoot([]),
    SpartacusModule,
    BrowserTransferStateModule,
    BrxModule,
    BrxSpartacusLibModule.forRoot({ ...environment }),
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
src/app/app.component.ts

In the app-root component, you'll need to pass the configuration and Content components mapping into the br-page component inputs.

import {
  Component,
  Inject,
  InjectionToken,
  OnInit,
  Optional,
} from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { BrPageComponent } from '@bloomreach/ng-sdk';
import { Page } from '@bloomreach/spa-sdk';
import { REQUEST } from '@nguniversal/express-engine/tokens';
import { OutletPosition } from '@spartacus/storefront';
import { Request } from 'express';
import { Observable } from 'rxjs';
import { filter, tap } from 'rxjs/operators';
import { SpartacusBannerComponent } from '@bloomreach/brx-spartacus-library';
import { HttpErrorResponse } from '@angular/common/http';
import { PageContext, RoutingService } from '@spartacus/core';

export const ENDPOINT = new InjectionToken<string>('brXM API endpoint');

@Component({
  selector: "app-root",
  template: `
    <ng-container *ngIf="pageContext$ | async as pageContext">
        <br-page
            [configuration]="configuration"
            [mapping]="mapping"
            (httpError)="onBrxHttpError($event)"
            (state)="setVisitor($event)"
        >
            <ng-template let-page="page">
                <app-header></app-header>
                    <div *ngIf="!pageContext.id.includes('search')">
                    <ng-container brComponent="main"></ng-container>
                    </div>
                    <div *ngIf="pageContext.id.includes('search')">
                    <ng-container brComponent="top"></ng-container>
                    <div class="ProductListPageTemplate">
                        <div class="ProductLeftRefinements">
                        <ng-container brComponent="left"></ng-container>
                        </div>
                        <div class="ProductListSlot">
                        <ng-container brComponent="right"></ng-container>
                        </div>
                    </div>
                    <ng-container brComponent="bottom"></ng-container>
                    </div>
                <app-footer></app-footer>
            </ng-template>
        </br-page>
    </ng-container>
  `,
})
export class AppComponent {
configuration: BrPageComponent['configuration'];

  outletPosition = OutletPosition;

  mapping = {
    SpartacusBanner: SpartacusBannerComponent
  };

  page?: Page;

  brxHttpError?: HttpErrorResponse;

  pageContext$?: Observable<PageContext>;

  private navigationEnd: Observable<NavigationEnd>;

  constructor(
    router: Router,
    private routingService: RoutingService,
    @Inject(ENDPOINT) endpoint?: string,
    @Inject(REQUEST) @Optional() request?: Request
  ) {
    this.configuration = {
      debug: true,
      endpoint,
      request,
      endpointQueryParameter: 'endpoint',
      path: router.url,
    } as BrxComponent['configuration'];

    this.navigationEnd = router.events.pipe(
      filter((event) => event instanceof NavigationEnd)
    ) as Observable<NavigationEnd>;
  }

  ngOnInit(): void {
    this.navigationEnd.subscribe((event) => {
      this.configuration = { ...this.configuration, path: event.url };
      this.brxHttpError = undefined;
      this.pageContext$ = this.routingService.getPageContext().pipe(
        tap((pageContext) => console.log('[BrxComponent.PageContext]: ', pageContext))
      );
    });
  }

  setVisitor(page?: Page): void {
    this.configuration.visitor = page?.getVisitor();
  }

  onBrxHttpError(error: HttpErrorResponse): void {
    this.brxHttpError = error;
  }
}

Mapping

The br-page component provides a way to link Angular components with the custom built Content Spartacus ones. You'll need to pass the mapping property which maps the component type with its representation.

import { SpartacusBannerComponent } from '@bloomreach/brx-spartacus-library';

export class AppComponent {
  mapping = {
    SpartacusBanner: SpartacusBannerComponent
  };
}

Configuration

The Enviroment Variables to be confirured are as follows :

PropertyRequiredDescription
endpointyesThe Content endpoint.
smEndPointyesThe Discovery endpoint.
smSuggestionEndPointyesThe Discovery Suggestion endpoint.
accountIdyesThe Discovery account ID.
domainKeyyesThe Discovery domain key.
authKeyyesThe Discovery auth key.
smPathwaysRecommendationsEndPointyesThe Discovery Pathways and Recommendations endpoint.

Example

export const environment = {
  endpoint: 'https://...../pages',
  smEndPoint: 'https://....',
  smSuggestionEndPoint: 'https://suggest.xyzz.com/api/',
  accountId : "1234",
  domainKey : "abc_123",
  authKey : "etdr235dfh",
};

License

Published under Apache 2.0 license.

Keywords

FAQs

Package last updated on 10 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc