Skip to main content

API & Services

How the app talks to its backend, and the shared services that support it.


API Client​

Central HTTP client (Axios 1.10.0) used for all REST calls.

Location: libs/shared/src/services/api/apiClient.js Import: import { apiClient } from '@aquagen-mf-webapp/shared/services';

  • Base URL: selected by constants.currentEnv (see Environment URLs); defaults to production.
  • Timeout: 50 s (constants.request.defaultTimeout).
  • Auth: JWT bearer token attached automatically.

Methods​

import { apiClient } from '@aquagen-mf-webapp/shared/services';

await apiClient.get(url, params, headers, customConfig);
await apiClient.post(url, body, params, headers, customConfig);
await apiClient.put(url, body, params, headers, customConfig);
await apiClient.patch(url, body, params, headers, customConfig);
await apiClient.del(url, params, headers, customConfig);
await apiClient.postFile(url, file, fieldName, params, headers, customConfig);

All six are attached to apiClient (get, post, put, patch, del, postFile).

Request interceptor​

Every request automatically gets the JWT Authorization header plus device headers (from deviceFingerprint). The header names are exactly:

HeaderValue
AuthorizationBearer <jwt>
browserNamebrowser name
browserVersionbrowser version
deviceTypedesktop / mobile
operationSystemOS
deviceIddevice fingerprint
x-request-idper-request id
note

These are the literal header keys in apiClient.js — they are not x- prefixed (except x-request-id). Don't add them manually; the interceptor does.

Response interceptor — status handling​

StatusMeaning
200Success
400Bad request
401Unauthorized → session expired, redirect to login
402 / 420Payment/subscription required
440Token expired
500Server error

(Codes and messages are defined in constants.request.error — see Enums & Configs.)


Core Services​

All are re-exported from @aquagen-mf-webapp/shared/services (libs/shared/src/services/index.js).

Analytics — AnalyticsService​

Tracks user events across three providers: Google Analytics, Firebase, and Mixpanel.

Location: libs/shared/src/services/analytics/analyticsService.js

import { AnalyticsService } from '@aquagen-mf-webapp/shared/services';
import { AnalyticEvents } from '@aquagen-mf-webapp/shared/enums';

// signature: sendEvent(event, props, pageView = false)
AnalyticsService.sendEvent(AnalyticEvents.DASHBOARD_CARD_CLICK, { card: 'energy' });

// a page view sets the boolean 3rd argument (there is no separate pageView method)
AnalyticsService.sendEvent(AnalyticEvents.PAGE_VIEW, {}, true);

See Analytics Events for the full event catalog.

Device Fingerprint​

Generates the stable deviceId and browser/OS values used in request headers (via FingerprintJS).

Location: libs/shared/src/services/deviceFingerprint/deviceFingerprint.js

WebSocket​

Real-time updates via Azure Web PubSub (wss://*.webpubsub.azure.com).

Location: libs/shared/src/services/websocket/websocket.js

Local Storage — LocalDBInstance / LocalDBKeys​

Wrapper over localStorage with a fixed set of keys.

Location: libs/shared/src/services/localdb/localdb.js

import { LocalDBInstance, LocalDBKeys } from '@aquagen-mf-webapp/shared/services';

LocalDBInstance.setItem(LocalDBKeys.loginResponse, data);
const raw = LocalDBInstance.getItem(LocalDBKeys.loginResponse);
LocalDBInstance.removeItem(LocalDBKeys.loginResponse);

Session Storage​

sessionStorage wrapper, session-scoped equivalent of LocalDB.

Location: libs/shared/src/services/sessionStorage/sessionStorage.js

Notifications​

Browser notification permission + display.

Location: libs/shared/src/services/notificationUtil.js


Endpoints​

Endpoints are defined as getters on the Urls singleton in libs/shared/src/services/api/urls.js and passed to apiClient:

import { apiClient, Urls } from '@aquagen-mf-webapp/shared/services';

const data = await apiClient.get(Urls.dashboardData); // → /landingPage/userData

Paths are relative to the base URL (.../api/user/) unless noted. This is the authoritative list from urls.js — the getter name is the property you call on Urls.

Auth

GetterPath
loginuser/login
validateCredentialsuser/validateCredentials
otpPhnCheckuser/otplogin
refreshTokenuser/refresh
logoutuser/logout

Dashboard & monitoring

GetterPath
dashboardData/landingPage/userData
categoryDatadeviceData/
categoryDataV2deviceDataV2
compareData/deviceDataV2/compare
getGranularCategoryData / granularCategoryDatagranular/category
getGranularUnitData / granularUnitDatagranular/unit
getGroundWaterGraphDatagroundWaterLevel/graph
getVirtualNodesData / postVirtualNodesDatavirtual/device_data

Alerts & notifications

GetterPath
getAlertsalerts
getAlertsByDateRangealerts/dateRange
getLeakageAlertsDataalerts/unitGraph
notificationDatanotification/
notificationDataByRange/notificationRange
updateNotificationReadnotification/updateRead
assignNotification/notification/assignee

Water features

GetterPath
waterBalanceDatawaterBalance/data
getNeutralityDataneutrality/
getWaterRatioData / postWaterRatioData / putWaterRatioData/waterRatio/
gwiDatagwi/data
getRainefficiencysavingsdata/rainfall/efficiencySaving
getRainFallTrend/rainfall/trend

Lake / WRI / ILM

GetterPath
lakeListwri/lakeList
calculateVolumeAndBathymetrywri/bathymetryResult
wriDatesListwri/datesList
wriSatelliteDatawri/satelliteData
asvDates / asvQualitywri/asv/dates · wri/asv/quality
ilmPointTrendswri/ilm/pointTrends
ilmTrendWaterAvailabilitywri/ilm/trendWaterAvailability

AI (AquaGPT)

GetterPath
getGptResponsegpt/aqua
getGptStreamResponsegpt/stream/aqua
getGptPastResponsegpt/responses/ndays

Leadership / executive

GetterPath
getExecutiveDataexecutiveSummary/data
executiveIndustryLoginexecutiveSummary/login
putExecutivePinexecutiveSummary/pin

Energy / UWI / UWMS

GetterPath
getEnergyDashboardData / getUwidashboardData / getAquaLabsData/deviceDataV2
getEnergySavedUwiData/deviceData
uwmsStatsuwms/stats
uwmsControlLogsuwms/control-logs

RO efficiency

GetterPath
roEfficiencyData/roEfficiency/
getLogActivities / postLogActivity/roEfficiency/logActivities

SCADA / HMI / PLC

GetterPath
scadaGraphEditorscada/graphEditor
scadaDatascada/data
hmiDeviceValues / postHmiParamValuehmi
plcWriteRegistersplc/write-registers
plcEventHubData(full admin URL — different host)

Account, subscription, reports & misc

GetterPath
accountSettingsUpdateaccounts/settings
accountSettingsLogoUpdate/accounts/logoupdate
accountDetailsaccounts/landingpage
lastUpdatedTimeaccounts/info/lastupdated
getSubscriptionDetails/subscription/
postAquaLabsReportdataExtraction/
getAquaLabsReports/dataExtraction/reports
reportUrl(...)report builder — separate host, not the base URL
sendMail/sendMail
note

urls.js is the source of truth. If a getter isn't listed here, check the file directly — and the report download (reportUrl(...)) and plcEventHubData point at their own hosts, not the /api/user/ base.


Environment URLs​

Urls.baseUrl switches on constants.currentEnv:

currentEnvBase URL
prodhttps://prod-aquagen.azurewebsites.net/api/user/
devhttps://dev2-aquagenapi.azurewebsites.net/api/user/
localhttp://localhost:5001/api/user/
demohttps://aqua-demo-api-djeaedfdh3gjhzey.centralindia-01.azurewebsites.net/api/user/
ngrokngrok tunnel

Separate backends: AI agent (getAIAgentBaseUrl() → .../ai-agent-backend... or localhost:8000) and UWI AI (uwiAIBaseUrl). See Local environment & backend switching.

Location: libs/shared/src/services/api/urls.js


Integration pattern​

Component → Store (Context) → Controller → DataSource → apiClient (Axios) → Backend

Keep API calls in the DataSource layer; components go through the store, not apiClient directly.


Next Steps​