@a-cube-io/ereceipts-js-sdk 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +50 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +16 -10
- package/dist/index.esm.js +50 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.js +50 -3
- package/dist/index.native.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -7651,6 +7651,10 @@ class AxiosHttpAdapter {
|
|
|
7651
7651
|
this.client.interceptors.request.use((config) => {
|
|
7652
7652
|
if (this.authToken) {
|
|
7653
7653
|
config.headers.Authorization = `Bearer ${this.authToken}`;
|
|
7654
|
+
log$2.debug('Adding JWT token to request');
|
|
7655
|
+
}
|
|
7656
|
+
else {
|
|
7657
|
+
log$2.warn('No JWT token available for request:', { url: config.url });
|
|
7654
7658
|
}
|
|
7655
7659
|
const method = config.method?.toUpperCase() ?? 'UNKNOWN';
|
|
7656
7660
|
log$2.debug(`→ ${method} ${config.url}`);
|
|
@@ -7746,6 +7750,7 @@ class AxiosHttpAdapter {
|
|
|
7746
7750
|
return this.mapResponse(response);
|
|
7747
7751
|
}
|
|
7748
7752
|
setAuthToken(token) {
|
|
7753
|
+
log$2.info('setAuthToken called:', { hasToken: !!token, tokenPrefix: token?.substring(0, 20) });
|
|
7749
7754
|
this.authToken = token;
|
|
7750
7755
|
}
|
|
7751
7756
|
getAuthToken() {
|
|
@@ -8719,6 +8724,35 @@ class SDKManager {
|
|
|
8719
8724
|
this.telemetryService = null;
|
|
8720
8725
|
this.appStateService = null;
|
|
8721
8726
|
this.isInitialized = false;
|
|
8727
|
+
this.isPollingActive = false;
|
|
8728
|
+
/**
|
|
8729
|
+
* Handle user state changes (login/logout/token expiration)
|
|
8730
|
+
* Manages polling lifecycle based on user role
|
|
8731
|
+
*/
|
|
8732
|
+
this.handleUserChanged = async (user) => {
|
|
8733
|
+
// Always call user's event handler first
|
|
8734
|
+
this.events?.onUserChanged?.(user);
|
|
8735
|
+
if (!this.isInitialized)
|
|
8736
|
+
return;
|
|
8737
|
+
if (user) {
|
|
8738
|
+
// User logged in - check role and start polling if allowed
|
|
8739
|
+
const canPoll = hasAnyRole(user.roles, ['ROLE_MERCHANT', 'ROLE_CASHIER']);
|
|
8740
|
+
if (canPoll && !this.isPollingActive) {
|
|
8741
|
+
this.notificationService?.startPolling();
|
|
8742
|
+
await this.startTelemetryPollingAuto();
|
|
8743
|
+
this.isPollingActive = true;
|
|
8744
|
+
}
|
|
8745
|
+
}
|
|
8746
|
+
else {
|
|
8747
|
+
// User logged out or token expired - stop polling
|
|
8748
|
+
if (this.isPollingActive) {
|
|
8749
|
+
this.notificationService?.stopPolling();
|
|
8750
|
+
this.telemetryService?.stopPolling();
|
|
8751
|
+
this.telemetryService?.clearTelemetry();
|
|
8752
|
+
this.isPollingActive = false;
|
|
8753
|
+
}
|
|
8754
|
+
}
|
|
8755
|
+
};
|
|
8722
8756
|
}
|
|
8723
8757
|
/**
|
|
8724
8758
|
* Configure the SDKManager singleton
|
|
@@ -8762,7 +8796,12 @@ class SDKManager {
|
|
|
8762
8796
|
async initialize() {
|
|
8763
8797
|
if (this.isInitialized)
|
|
8764
8798
|
return;
|
|
8765
|
-
|
|
8799
|
+
// Wrap events to intercept onUserChanged for polling lifecycle management
|
|
8800
|
+
const wrappedEvents = {
|
|
8801
|
+
...this.events,
|
|
8802
|
+
onUserChanged: this.handleUserChanged,
|
|
8803
|
+
};
|
|
8804
|
+
this.sdk = new ACubeSDK(this.config, this.adapters, wrappedEvents);
|
|
8766
8805
|
await this.sdk.initialize();
|
|
8767
8806
|
const adaptersRef = this.sdk.getAdapters();
|
|
8768
8807
|
if (!adaptersRef) {
|
|
@@ -8786,8 +8825,15 @@ class SDKManager {
|
|
|
8786
8825
|
this.telemetryService.state$.subscribe(this.events.onTelemetryStateChanged);
|
|
8787
8826
|
}
|
|
8788
8827
|
this.isInitialized = true;
|
|
8789
|
-
|
|
8790
|
-
this.
|
|
8828
|
+
// Only start polling for MERCHANT/CASHIER users (SUPPLIER gets 401 on these endpoints)
|
|
8829
|
+
const user = await this.sdk.getCurrentUser();
|
|
8830
|
+
const canPoll = user && hasAnyRole(user.roles, ['ROLE_MERCHANT', 'ROLE_CASHIER']);
|
|
8831
|
+
if (canPoll) {
|
|
8832
|
+
this.notificationService.startPolling();
|
|
8833
|
+
await this.startTelemetryPollingAuto();
|
|
8834
|
+
this.isPollingActive = true;
|
|
8835
|
+
}
|
|
8836
|
+
// AppStateService remains active for all users (handles OFFLINE network state)
|
|
8791
8837
|
}
|
|
8792
8838
|
/**
|
|
8793
8839
|
* Observable stream of app state
|
|
@@ -8939,6 +8985,7 @@ class SDKManager {
|
|
|
8939
8985
|
this.appStateService = null;
|
|
8940
8986
|
this.sdk = null;
|
|
8941
8987
|
this.isInitialized = false;
|
|
8988
|
+
this.isPollingActive = false;
|
|
8942
8989
|
}
|
|
8943
8990
|
ensureInitialized() {
|
|
8944
8991
|
if (!this.isInitialized) {
|