This document details the platform.identity library. This package handles user identity management for your Angular application. It provides tools for managing authentication, user profiles, and associated data. The package leverages NgRx for state management (with actions, effects, reducers, selectors, and facades), defines API routes and service implementations (both live and mock), and delivers reusable UI components for identity interactions.
The platform.identity package provides a comprehensive solution for managing identity-related functionality in your application. Key features include:
This package is designed to seamlessly integrate with your Angular application in both production and development environments.
A high-level overview of the package layout:
.eslintrc.json, jest.config.ts, ng-package.json, package.json, project.jsontsconfig.json, tsconfig.lib.json, tsconfig.lib.prod.json, tsconfig.spec.jsonindex.ts – Main entry point re-exporting the module and library API.test-setup.ts – Configuration for Jest.IDENTITY_ACTION_IDENTIFIER) for use in actions and reducers.createNamespacedFeatureKey) to register state features for both admin and enduser domains..live() or .mock()) for specifying whether to use live or mock API services.The identity package uses NgRx to maintain state consistency for authentication and profile data.
IDENTITY_ACTION_IDENTIFIER and keys for various state slices (e.g., admin-user and enduser state).Identity actions are divided primarily into admin-user and enduser groups.
createAdminUser: Initiates the creation of an admin user.updateAdminUser: Updates details for an existing admin user.deleteAdminUser: Removes an admin user.resetAdminUserFilters: Resets any filter state applied to admin user lists.createAction and include required payloads (e.g. user credentials, profile data).listEndusers: Dispatches a request to load a list of endusers (optionally with pagination).selectEnduser: Selects an individual enduser by ID.updateEnduserFilters: Updates the filter criteria for enduser queries.resetEnduserFilters: Clears any applied filters.createAction and are tailored to handle enduser state.admin-user.effects.ts might handle admin user creation, update, or deletion workflows.enduser.effects.ts handle fetching enduser lists and detailed profiles.switchMap, map, and catchError are used to send and process API responses.resetAdminUserFilters are dispatched.createReducer and on functions.createSelector to generate memoized state slices.Facades provide a higher-level interface for interacting with identity state without directly dispatching actions or subscribing to selectors.
adminUserFilters$: Streams current admin user filter settings.adminUserRemotePagination$: Provides pagination details for the admin user list.adminUsers$: An observable stream of all admin user records.selectedAdminUser$: Returns the currently selected admin user.loggedInAdminUser$, hasLoggedInAdminUser$, loggedInAdminUserName$: Observables for authentication state.resetAdminUserFilters(): Dispatches an action to clear admin user filters.enduserFilters$: Provides current filter settings for endusers.enduserRemotePagination$: Streams pagination info.endusers$: Collection of enduser records.selectedEnduser$: The currently selected enduser.selectedEnduserId$: Observable for the selected enduser ID.enduserById$(id: string): Function returning an observable for a specific enduser.listEndusers(pagination?: Nullable<Partial<PaginatedQueryParams<Model.EnduserResponse>>>): void: Dispatches an action to list endusers.selectEnduser(enduserId: string): void: Dispatches an action to select an enduser.updateEnduserFilters(filters: Partial<Model.EnduserFilters>): void: Dispatches an action to update filters.resetEnduserFilters(): void: Dispatches an action to clear filters.enduserAddressFilters$, enduserAddressRemotePagination$, enduserAddresses$, selectedEnduserAddress$, filteredEnduserAddresses$: Provide reactive streams for address-related state.createEnduserAddress(enduserId: string, request: Model.CreateEnduserAddressRequest): void: Dispatches an action to create a new enduser address.listEnduserAddresses(enduserId: string, pagination?: Nullable<Partial<PaginatedQueryParams<Model.EnduserAddressResponse>>>): void: Dispatches an action to list addresses.updateEnduserAddressFilters(filters: Partial<Model.EnduserAddressFilters>): void: Dispatches an action to update address filter criteria.enduserSessionFilters$, enduserSessionRemotePagination$, enduserSessionRemoteState$, enduserSessions$, selectedEnduserSession$, and a helper enduserSessionById$(id: string) observable.Note: Additional facades (e.g., EnduserCredentialFacade, EnduserDeviceFacade, EnduserEmailFacade, EnduserPhoneFacade) are exported and available via the facades index. Each follows similar patterns of exposing selectors as observables and methods that dispatch actions.
Models in the identity package define the shape of identity-related data:
model/.api-routes/ folder, these files centralize endpoint definitions for identity. This may include routes for admin user operations, enduser data fetches, and other identity tasks.IDENTITY_API_CONFIG). These tokens are used in module configuration to determine API endpoints for live or mock modes.Services implement the actual API calls for identity operations. Both live and mock service implementations exist to support production and development use cases.
Services are provided via factory providers declared in the module, ensuring that the appropriate implementation (live or mock) is used based on configuration.
nx build platform.identity
nx test platform.identity
import { PlatformIdentityModule } from '@zwp/platform.identity';
@NgModule({
imports: [
// For production:
PlatformIdentityModule.live(),
// For development/testing:
// PlatformIdentityModule.mock()
]
})
export class AppModule {}
constructor(private enduserFacade: EnduserFacade) {}
loadUsers() {
this.enduserFacade.listEndusers();
}
The platform.identity package offers a powerful, scalable solution for managing user identity within your Angular application. With well-organized NgRx state management (actions, effects, reducers, selectors, and facades), robust model definitions, centralized API routes, and flexible service implementations, it supports both admin and enduser domains. Detailed facade methods further simplify integration with your component logic.