@fluxo-dev/api-client-base 25.4.3 → 26.1.1
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/index.cjs.js +105 -13
- package/package.json +2 -2
- package/src/lib/session-hub/session-hub.service.d.ts +19 -0
package/index.cjs.js
CHANGED
|
@@ -2667,6 +2667,10 @@ let HttpClient$1 = class HttpClient {
|
|
|
2667
2667
|
return config;
|
|
2668
2668
|
}));
|
|
2669
2669
|
this._axiosInstance.interceptors.response.use(response => response.data, error => {
|
|
2670
|
+
if (error.code === 'ERR_NETWORK') return Promise.reject({
|
|
2671
|
+
code: "ERR_NETWORK",
|
|
2672
|
+
message: "Il server non è raggiungibile."
|
|
2673
|
+
});
|
|
2670
2674
|
if (error.response.status === 401) ;
|
|
2671
2675
|
return Promise.reject({
|
|
2672
2676
|
code: error.response.status,
|
|
@@ -9698,6 +9702,8 @@ class SessionHubService {
|
|
|
9698
9702
|
this.eventHandlers = new Map();
|
|
9699
9703
|
this.reconnectTimeoutId = null;
|
|
9700
9704
|
this.isManualStop = false; // Flag to prevent reconnection after manual stop (e.g., logout)
|
|
9705
|
+
this.hasReachedMaxAttempts = false; // Flag to track if max attempts reached
|
|
9706
|
+
this.useAutomaticReconnect = true; // Flag to control automatic reconnection behavior
|
|
9701
9707
|
this.hubUrl = `${baseUrl}/ws/session`;
|
|
9702
9708
|
this.getAccessToken = getAccessToken;
|
|
9703
9709
|
}
|
|
@@ -9723,27 +9729,50 @@ class SessionHubService {
|
|
|
9723
9729
|
const deviceId = DeviceIdManager.getDeviceId();
|
|
9724
9730
|
// Aggiungi device-id come query parameter all'URL
|
|
9725
9731
|
const hubUrlWithDeviceId = `${this.hubUrl}?deviceId=${encodeURIComponent(deviceId)}`;
|
|
9726
|
-
|
|
9732
|
+
const builder = new HubConnectionBuilder().withUrl(hubUrlWithDeviceId, {
|
|
9727
9733
|
accessTokenFactory: () => this.getAccessToken(),
|
|
9728
9734
|
transport: HttpTransportType.WebSockets,
|
|
9729
9735
|
withCredentials: false
|
|
9730
|
-
})
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9736
|
+
});
|
|
9737
|
+
// Conditionally add automatic reconnect based on flag
|
|
9738
|
+
if (this.useAutomaticReconnect) {
|
|
9739
|
+
builder.withAutomaticReconnect({
|
|
9740
|
+
nextRetryDelayInMilliseconds: retryContext => {
|
|
9741
|
+
// Track attempts using SignalR's counter
|
|
9742
|
+
this.reconnectAttempts = retryContext.previousRetryCount + 1;
|
|
9743
|
+
// Stop after max attempts
|
|
9744
|
+
if (retryContext.previousRetryCount >= this.maxReconnectAttempts) {
|
|
9745
|
+
console.warn(`SessionHub: Max automatic reconnection attempts (${this.maxReconnectAttempts}) reached`);
|
|
9746
|
+
this.hasReachedMaxAttempts = true;
|
|
9747
|
+
this.useAutomaticReconnect = false; // Disable for next connection
|
|
9748
|
+
return null; // Stop automatic reconnection
|
|
9749
|
+
}
|
|
9750
|
+
// Exponential backoff: 0, 2, 10 seconds, then 5 seconds
|
|
9751
|
+
if (retryContext.previousRetryCount === 0) return 0;
|
|
9752
|
+
if (retryContext.previousRetryCount === 1) return 2000;
|
|
9753
|
+
if (retryContext.previousRetryCount === 2) return 10000;
|
|
9754
|
+
return this.reconnectDelay;
|
|
9755
|
+
}
|
|
9756
|
+
});
|
|
9757
|
+
}
|
|
9758
|
+
this.connection = builder.configureLogging(LogLevel.Information).build();
|
|
9739
9759
|
this.setupConnectionHandlers();
|
|
9740
9760
|
this.reattachEventHandlers();
|
|
9741
9761
|
yield this.connection.start();
|
|
9742
9762
|
console.info('SessionHub: Connection established successfully with device-id:', deviceId);
|
|
9743
9763
|
this.reconnectAttempts = 0;
|
|
9764
|
+
this.hasReachedMaxAttempts = false;
|
|
9765
|
+
// Re-enable automatic reconnect for future disconnections
|
|
9766
|
+
this.useAutomaticReconnect = true;
|
|
9744
9767
|
} catch (error) {
|
|
9745
9768
|
console.error('SessionHub: Error starting connection', error);
|
|
9746
|
-
|
|
9769
|
+
// Only schedule reconnect if in automatic mode
|
|
9770
|
+
if (this.useAutomaticReconnect && !this.hasReachedMaxAttempts) {
|
|
9771
|
+
this.scheduleReconnect();
|
|
9772
|
+
} else {
|
|
9773
|
+
// Manual mode: just set flag for UI
|
|
9774
|
+
this.hasReachedMaxAttempts = true;
|
|
9775
|
+
}
|
|
9747
9776
|
}
|
|
9748
9777
|
});
|
|
9749
9778
|
}
|
|
@@ -9861,6 +9890,51 @@ class SessionHubService {
|
|
|
9861
9890
|
var _a, _b;
|
|
9862
9891
|
return (_b = (_a = this.connection) === null || _a === void 0 ? void 0 : _a.connectionId) !== null && _b !== void 0 ? _b : null;
|
|
9863
9892
|
}
|
|
9893
|
+
/**
|
|
9894
|
+
* Get current reconnection attempts count
|
|
9895
|
+
*/
|
|
9896
|
+
get currentReconnectAttempts() {
|
|
9897
|
+
return this.reconnectAttempts;
|
|
9898
|
+
}
|
|
9899
|
+
/**
|
|
9900
|
+
* Get max reconnection attempts limit
|
|
9901
|
+
*/
|
|
9902
|
+
get maxReconnectAttemptsLimit() {
|
|
9903
|
+
return this.maxReconnectAttempts;
|
|
9904
|
+
}
|
|
9905
|
+
/**
|
|
9906
|
+
* Check if max reconnection attempts have been reached
|
|
9907
|
+
*/
|
|
9908
|
+
get hasReachedMaxReconnectAttempts() {
|
|
9909
|
+
return this.hasReachedMaxAttempts;
|
|
9910
|
+
}
|
|
9911
|
+
/**
|
|
9912
|
+
* Manually retry connection - performs single connection attempt without automatic retries
|
|
9913
|
+
* User must click retry button again if connection fails
|
|
9914
|
+
*/
|
|
9915
|
+
manualRetry() {
|
|
9916
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9917
|
+
console.info('SessionHub: Manual retry initiated by user');
|
|
9918
|
+
// Reset counters and flags
|
|
9919
|
+
this.reconnectAttempts = 0;
|
|
9920
|
+
this.hasReachedMaxAttempts = false;
|
|
9921
|
+
this.isManualStop = false;
|
|
9922
|
+
this.useAutomaticReconnect = false; // Force manual mode - no automatic retries
|
|
9923
|
+
// Cancel any pending reconnection attempt
|
|
9924
|
+
if (this.reconnectTimeoutId) {
|
|
9925
|
+
clearTimeout(this.reconnectTimeoutId);
|
|
9926
|
+
this.reconnectTimeoutId = null;
|
|
9927
|
+
}
|
|
9928
|
+
// Attempt to start connection (will be without automatic reconnect)
|
|
9929
|
+
try {
|
|
9930
|
+
yield this.start();
|
|
9931
|
+
} catch (error) {
|
|
9932
|
+
console.error('SessionHub: Manual retry failed', error);
|
|
9933
|
+
// Set flag so UI shows retry button again
|
|
9934
|
+
this.hasReachedMaxAttempts = true;
|
|
9935
|
+
}
|
|
9936
|
+
});
|
|
9937
|
+
}
|
|
9864
9938
|
/**
|
|
9865
9939
|
* Setup connection lifecycle handlers
|
|
9866
9940
|
*/
|
|
@@ -9868,14 +9942,30 @@ class SessionHubService {
|
|
|
9868
9942
|
if (!this.connection) return;
|
|
9869
9943
|
this.connection.onclose(error => {
|
|
9870
9944
|
console.warn('SessionHub: Connection closed', error);
|
|
9871
|
-
|
|
9945
|
+
// Don't schedule reconnect if in manual mode - user must click retry button
|
|
9946
|
+
if (!this.useAutomaticReconnect) {
|
|
9947
|
+
console.info('SessionHub: In manual mode - waiting for user to retry');
|
|
9948
|
+
this.hasReachedMaxAttempts = true;
|
|
9949
|
+
return;
|
|
9950
|
+
}
|
|
9951
|
+
// In automatic mode, check if we've reached max attempts
|
|
9952
|
+
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
9953
|
+
console.error('SessionHub: Max reconnection attempts reached');
|
|
9954
|
+
this.hasReachedMaxAttempts = true;
|
|
9955
|
+
this.useAutomaticReconnect = false;
|
|
9956
|
+
} else {
|
|
9957
|
+
// Schedule next reconnect attempt
|
|
9958
|
+
this.scheduleReconnect();
|
|
9959
|
+
}
|
|
9872
9960
|
});
|
|
9873
9961
|
this.connection.onreconnecting(error => {
|
|
9874
|
-
console.warn(
|
|
9962
|
+
console.warn(`SessionHub: Attempting to reconnect... (attempt ${this.reconnectAttempts} of ${this.maxReconnectAttempts})`, error);
|
|
9875
9963
|
});
|
|
9876
9964
|
this.connection.onreconnected(connectionId => {
|
|
9877
9965
|
console.info(`SessionHub: Reconnected successfully. ConnectionId: ${connectionId}`);
|
|
9878
9966
|
this.reconnectAttempts = 0;
|
|
9967
|
+
this.hasReachedMaxAttempts = false;
|
|
9968
|
+
this.useAutomaticReconnect = true; // Re-enable automatic reconnect
|
|
9879
9969
|
});
|
|
9880
9970
|
}
|
|
9881
9971
|
/**
|
|
@@ -9900,6 +9990,8 @@ class SessionHubService {
|
|
|
9900
9990
|
}
|
|
9901
9991
|
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
9902
9992
|
console.error('SessionHub: Max reconnection attempts reached. Giving up.');
|
|
9993
|
+
this.hasReachedMaxAttempts = true;
|
|
9994
|
+
this.useAutomaticReconnect = false; // Disable automatic reconnect
|
|
9903
9995
|
return;
|
|
9904
9996
|
}
|
|
9905
9997
|
this.reconnectAttempts++;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxo-dev/api-client-base",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.1.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"react": "^18.3.1",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"react-router-dom": "^6.11.2",
|
|
9
9
|
"react-redux": "^8.0.5",
|
|
10
10
|
"@reduxjs/toolkit": "^1.9.1",
|
|
11
|
-
"@fluxo-dev/state": "^
|
|
11
|
+
"@fluxo-dev/state": "^26.1.1"
|
|
12
12
|
},
|
|
13
13
|
"main": "./index.cjs.js",
|
|
14
14
|
"types": "./index.cjs.d.ts"
|
|
@@ -13,6 +13,8 @@ export declare class SessionHubService {
|
|
|
13
13
|
private eventHandlers;
|
|
14
14
|
private reconnectTimeoutId;
|
|
15
15
|
private isManualStop;
|
|
16
|
+
private hasReachedMaxAttempts;
|
|
17
|
+
private useAutomaticReconnect;
|
|
16
18
|
constructor(baseUrl: string, getAccessToken: () => string);
|
|
17
19
|
getConnectedUsers(): Promise<{
|
|
18
20
|
userId: string;
|
|
@@ -75,6 +77,23 @@ export declare class SessionHubService {
|
|
|
75
77
|
* Get the connection ID
|
|
76
78
|
*/
|
|
77
79
|
get connectionId(): string | null;
|
|
80
|
+
/**
|
|
81
|
+
* Get current reconnection attempts count
|
|
82
|
+
*/
|
|
83
|
+
get currentReconnectAttempts(): number;
|
|
84
|
+
/**
|
|
85
|
+
* Get max reconnection attempts limit
|
|
86
|
+
*/
|
|
87
|
+
get maxReconnectAttemptsLimit(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Check if max reconnection attempts have been reached
|
|
90
|
+
*/
|
|
91
|
+
get hasReachedMaxReconnectAttempts(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Manually retry connection - performs single connection attempt without automatic retries
|
|
94
|
+
* User must click retry button again if connection fails
|
|
95
|
+
*/
|
|
96
|
+
manualRetry(): Promise<void>;
|
|
78
97
|
/**
|
|
79
98
|
* Setup connection lifecycle handlers
|
|
80
99
|
*/
|