This document details the Zastrozzi Rewards Network Merchant Net Library. This library is part of the Rewards Network module and provides functionality to manage merchants, their locations, assets, brands, categories, invoices, and more. It leverages NgRx state management, provides abstracted and live API service implementations, a comprehensive set of UI components, and centralized API routes, ensuring modularity and scalability in merchant data management.
The Rewards Network Merchant Net Library provides a complete solution for merchant data management within the Rewards Network suite. Its key features include:
MERCHANT_NET_API_CONFIG and MERCHANT_NET_API_BASE_URL) allow environment-specific settings.A high-level overview of the Rewards Network Merchant Net library layout:
.eslintrc.json
jest.config.ts
ng-package.json
package.json
project.json
README.md
tsconfig.json
tsconfig.lib.json
tsconfig.lib.prod.json
tsconfig.spec.json
src/
index.ts
test-setup.ts
lib/
rewards-network.merchant-net.module.ts // Main Angular module aggregating state, components, services, and API routes.
rewards-network.merchant-net.ts // Aggregates exports from state, services, components, and routes.
+state/
identifiers.ts // Defines namespaced keys and action identifiers.
index.ts // Re-exports state pieces.
state.ts // Combines reducers into a central state.
actions/ // Contains NgRx actions for merchant and related domains.
effects/ // Contains NgRx effects to handle asynchronous operations.
facades/ // Exposes high-level facades for state access.
reducers/ // Reducers for state transitions.
selectors/ // Memoized selectors for accessing state slices.
api-routes/ // Centralized API route definitions (merchant, asset, brand, category, location, etc.).
components/ // Reusable Angular components (merchant list, detail components, windows, etc.).
config/ // Configuration tokens (e.g. MERCHANT_NET_API_CONFIG).
model/ // Shared models, enums, requests, responses, and filters.
routes/ // Angular route definitions for merchant features.
services/ // Contains abstract, live, and mock API service implementations.
forRoot() method, accepting a configuration object (of type MerchantNetAPIConfig) to set API endpoints (local and remote) and to determine whether live or mock services should be used.The library uses NgRx to manage and centralize state across various merchant domains.
+state/identifiers.ts, keys such as MERCHANT_ACTION_IDENTIFIERS are used to namespace actions including creating, retrieving, listing, updating, and deleting merchants.createAction (with remote action groups for side effects). For example, actions like createMerchant, getMerchant, listMerchants, updateMerchant, deleteMerchant are defined in files under +state/actions/.+state/effects/) listen for dispatched remote actions and trigger API calls. For instance, the MerchantEffects class handles merchant creation, listing, updating, and deletion—often navigating to the correct route after successful actions.+state/reducers/) process state transformations in response to actions.+state/selectors/) provide memoized access to state slices such as the list of merchants, chosen merchant details, filters, and pagination data.Facades provide an abstraction layer over the NgRx store, exposing observable streams of state data and methods to dispatch actions. They encapsulate the logic for each domain and keep components decoupled from store internals.
merchants$: Emits an array of merchant records.selectedMerchant$: Emits the currently selected merchant, if any.merchantFilters$: Emits current filter settings used for querying merchants.merchantPagination$: Emits pagination metadata for the merchant list.merchantRemoteState$: Emits the remote API call state (e.g. loading, error, success).createMerchant(request: CreateMerchantRequest): voidgetMerchant(merchantId: string): voidlistMerchants(filters?: MerchantFilters, pagination?: Partial<PaginationParams>): voidupdateMerchant(merchantId: string, update: UpdateMerchantRequest): voiddeleteMerchant(merchantId: string, force?: boolean): voidselectMerchant(merchantId: string): voiddeselectMerchant(): voidupdateMerchantFilters(filters: Partial<MerchantFilters>, triggerFetch?: boolean): voidresetMerchantPagination(): voidassets$: Emits a list of asset items associated with merchants.createAsset(request: CreateAssetRequest): voidgetAsset(assetId: string): voidupdateAsset(assetId: string, update: UpdateAssetRequest): voiddeleteAsset(assetId: string): voidEach of these facades follows similar patterns:
createX, getX, updateX, deleteX, along with helper methods such as selectX and resetFilters for the respective domain (where X represents Brand, Category, or Location).For additional domains, facades provide a similar API:
API routes are centralized under api-routes/ and aggregate endpoints for all relevant domains:
Configuration tokens such as MERCHANT_NET_API_CONFIG and MERCHANT_NET_API_BASE_URL (defined in the config/ folder) are used to inject environment-specific settings into the API utilities.
The library offers a diverse collection of reusable Angular UI components, organized by feature groups. Each component is designed to work with the corresponding facades and services to ensure state synchronization and smooth UI interactions.
MerchantFacade to load and update merchant data.Each component is built to be highly configurable. They accept input properties for state, filters, and display options and emit events corresponding to user interactions (e.g., row click, form submission, or filter change), which are then handled by the corresponding facade methods.
The services layer provides the API client functionality:
MerchantLiveAPIService which implements operations such as createMerchant, getMerchant, listMerchants, updateMerchant, and deleteMerchant.services/abstract/ and injection tokens (e.g. MERCHANT_API_SERVICE) ensure the correct service implementation (live or mock) is provided based on the module configuration. nx build rewards-network.merchant-net
nx test rewards-network.merchant-net
import { RewardsNetworkMerchantNetModule } from '@zwp/rewards-network.merchant-net';
@NgModule({
imports: [
RewardsNetworkMerchantNetModule.forRoot({
remoteBaseUrl: 'https://api.remote.example.com',
localBaseUrl: 'http://localhost:3000',
apiState: 'live' // or 'mock'
}),
// other module imports...
]
})
export class AppModule {}
The Rewards Network Merchant Net Library offers a complete, scalable solution for managing merchant data within the Rewards Network. With robust NgRx state management, centralized API routes, configurable live and mock services, and a rich set of UI components, the library is designed for maintainability and rapid extension. Customize the components, facades, and services as our project requirements evolve.
Feel free to update or expand this documentation as needed.