Skip to main content

upp-base -- Overview

upp-base is the platform services layer for all Angular applications in the UnPisPas monorepo. It sits between the raw framework primitives (Angular, Ionic, Cordova) and the application code, providing a unified set of services for HTTP communication, persistent storage, localisation, geolocation, device management, WebSocket connectivity, and UI feedback. Every Angular app in the workspace -- unpispas-pos (production POS) and upp-test (demos and testing) -- imports upp-base as its foundation.

Why upp-base exists

Without upp-base, every application and feature library would need to solve the same set of cross-cutting concerns independently: how to make HTTP requests that work both in a browser and on a Cordova device, how to detect online/offline state, how to store data persistently across platforms, how to manage the user session, and how to present consistent UI feedback. upp-base centralises these solutions into a single, well-tested library so that:

  • Feature libraries (under libs/feature/) can focus on domain logic instead of platform plumbing.
  • Applications remain thin shells that compose features and services.
  • Cross-platform behaviour (browser vs. Cordova/Capacitor) is abstracted behind service APIs, so consuming code never needs to branch on the runtime environment.

Architecture and service dependency graph

All services in upp-base are providedIn: 'root' singletons. They are tree-shakeable -- if an application does not inject a service, it will not be bundled. The services form a layered dependency graph:

Layer 0 (no upp-base deps)       platformService, clockService, eventbusService, kioskService, configService, storeService
|
Layer 1 (depend on Layer 0) httpService (uses platformService)
toastService (uses languageService)
languageService (uses httpService, storeService)
|
Layer 2 (depend on Layer 1) stateService (standalone, but consumed by many)
adhocService (uses httpService, stateService, languageService, toastService, downloadService)
viewService (uses platformService, httpService, stateService, languageService, configService)
|
Layer 3 (depend on Layer 2) identificationService (uses adhocService, storeService)
geocodeService (uses httpService, platformService, alertService, toastService, languageService)
deviceService (uses httpService, adhocService)
uploadService / downloadService (uses httpService, languageService)
logsService (uses clockService, adhocService, viewService)
preloadService (uses stateService, viewService)

Understanding this graph helps you know which services are available at which point in the application lifecycle and which direction dependencies flow.

Module registration

The UppBaseModule must be imported in the root AppModule of every application. It bootstraps Ionic, Ionic Storage, and the Cordova plugin providers that the services depend on.

import { UppBaseModule } from '@unpispas/upp-base';

@NgModule({
imports: [
UppBaseModule,
// ...
]
})
export class AppModule {}

What the module provides

CategoryItems
DeclarationsmodalInputComponent, modalAlertComponent, UiKioskBoardComponent, UiKioskInputDirective, modalAwayComponent, UiAwayComponent
ExportsUiKioskInputDirective, UiKioskBoardComponent
Ionic modulesIonicModule.forRoot(), IonicStorageModule.forRoot()
ProvidersHTTP (Cordova), Network (Cordova), AndroidPermissions, Geolocation, provideHttpClient()

Dependencies

DependencyRole
@unpispas/upp-defsConstants (AppConstants) and utilities (GenericUtils). Zero-dependency foundation layer.
@ionic/angularUI primitives -- modals, toasts, loading indicators, platform detection.
@ionic/storage-angularKey-value persistent storage (IndexedDB / SQLite).
@awesome-cordova-plugins/*Cordova plugins: HTTP, Network, Geolocation, Android Permissions.
@angular/common/httpAngular HttpClient for browser-based HTTP requests.
ngx-device-detectorDevice-type detection (mobile / tablet / desktop).
@fingerprintjs/fingerprintjsBrowser fingerprinting for device identification.

Injection tokens

TokenTypeDescription
langsPathInjectionToken<string>Base path where language JSON files are stored. Must be provided by the consuming application so languageService knows where to load translation files from.
Storagevia IonicStorageModuleThe Ionic Storage driver. Automatically configured by IonicStorageModule.forRoot(). Used internally by storeService.

Services at a glance

All services are providedIn: 'root' (singleton, tree-shakeable).

ServiceKey roleWhen you will use it
httpServiceDual-mode HTTP transport (browser / Cordova), online/offline detection.Rarely directly -- prefer adhocService.
adhocServiceHigh-level request wrapper with automatic session, device, language, and place parameters.Every time you call the backend.
stateServiceApplication state: access mode, session, device, place, expiry, readiness.Login/logout flows, session management.
viewServiceView orchestration: current screen, edit mode, panels, theme, kiosk, SW updates.UI navigation, theme toggling, panel management.
languageServicei18n -- loads JSON translation modules, translates strings with placeholders.All user-facing text.
alertServiceModal alert dialogs with text, checkbox, and radio inputs.Confirmations, data entry prompts.
toastServiceToast notifications and loading indicators.User feedback for success, errors, long operations.
storeServiceKey-value persistent storage with per-key mutex (IndexedDB).Persisting session data, caches.
configServicePer-element configuration backed by localStorage.Small UI preferences (kiosk mode, theme).
platformServicePlatform detection (iOS, Android, desktop, Cordova), theme, zoom, kiosk.Adapting UI to the device.
identificationServiceFingerprintJS-based device identification.Device registration during login.
kioskServiceVirtual keyboard management.Touch-screen kiosk environments.
geocodeServiceGeolocation, Google Geocoding, timezone, NearBy proximity.Place setup, address resolution, proximity restriction.
deviceServiceLocal and remote WebSocket connections, printer/scale control.Peripheral device integration.
uploadServiceFile upload via multipart FormData.Attachment uploads.
downloadServiceFile download (server-proxied, base64-decoded).Report and document downloads.
clockServicePeriodic ticks (refresh, 1s, 10s, 1min).Polling, scheduled UI updates.
eventbusServiceGlobal event bus (emit / subscribe pattern).Cross-component communication without direct dependencies.
preloadServiceBackground image preloading with Cache API.Product images, media assets.
logsServiceClient-side log collection and server flushing.Debugging, support campaigns.

Importing

import { httpService, stateService, viewService, languageService } from '@unpispas/upp-base';

All public types, services, components, and directives are re-exported through libs/upp-base/src/index.ts. Import only what you need -- tree-shaking will remove the rest.

Typical application bootstrap flow

Understanding the order in which services initialise helps when debugging startup issues:

  1. platformService waits for the Ionic platform to be ready, then detects the runtime environment (mobile/desktop/cordova) and initialises theme and kiosk mode from configService.
  2. httpService starts onlineService, which immediately checks internet connectivity using either Cordova Network plugin events or browser online/offline events.
  3. viewService subscribes to session expiry events and loads the initial language modules via languageService.
  4. clockService starts its 250 ms base interval immediately on construction.
  5. logsService overrides window.console on construction. If a logging campaign was previously active (stored in localStorage), it resumes automatically.
  6. Application code sets stateService.device (via identificationService.DeviceId()), then performs login. On success, it sets stateService.session, stateService.Access, and viewService.View to transition the UI.
  7. stateService.IsReady is set to true once all initialisation is complete, which triggers preloadService to begin background image loading.