http-request-manager 18.13.25 → 18.13.26
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.
|
@@ -1165,20 +1165,20 @@ class QueryParamsTrackerService {
|
|
|
1165
1165
|
return;
|
|
1166
1166
|
}
|
|
1167
1167
|
this.stateRestored = true;
|
|
1168
|
-
this.initializeTrackingForSession();
|
|
1168
|
+
// this.initializeTrackingForSession();
|
|
1169
1169
|
this.restoreState();
|
|
1170
1170
|
}
|
|
1171
|
-
initializeTrackingForSession() {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
}
|
|
1171
|
+
// private initializeTrackingForSession(): void {
|
|
1172
|
+
// if (!this.hasSessionStorage()) {
|
|
1173
|
+
// return;
|
|
1174
|
+
// }
|
|
1175
|
+
// const initialized = sessionStorage.getItem(TRACKER_SESSION_INIT_KEY);
|
|
1176
|
+
// if (initialized === '1') {
|
|
1177
|
+
// return;
|
|
1178
|
+
// }
|
|
1179
|
+
// this.clearTracking();
|
|
1180
|
+
// sessionStorage.setItem(TRACKER_SESSION_INIT_KEY, '1');
|
|
1181
|
+
// }
|
|
1182
1182
|
restoreState() {
|
|
1183
1183
|
this.localStorageManager.store$(TRACKER_STORE_NAME)
|
|
1184
1184
|
.pipe(take(1))
|
|
@@ -7056,9 +7056,13 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7056
7056
|
}));
|
|
7057
7057
|
}
|
|
7058
7058
|
return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
|
|
7059
|
+
const forceRefresh = !!options?.forceRefresh;
|
|
7059
7060
|
const storedSchemaSignature = this.getStoredSchemaSignature(storeData);
|
|
7060
7061
|
const expires = storeData?.expires || 0;
|
|
7061
7062
|
const hasExpired = expires > 0 && this.utils.hasExpired(expires);
|
|
7063
|
+
if (forceRefresh) {
|
|
7064
|
+
return fetchFromAPI();
|
|
7065
|
+
}
|
|
7062
7066
|
if (hasExpired) {
|
|
7063
7067
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => fetchFromAPI()), tap(() => {
|
|
7064
7068
|
this.localStorageManagerService.updateStore({
|
|
@@ -7073,16 +7077,26 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7073
7077
|
const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
|
|
7074
7078
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchFromAPI()));
|
|
7075
7079
|
}
|
|
7076
|
-
const
|
|
7077
|
-
|
|
7080
|
+
const trackerAllowsRequest = this.queryParamsTrackerService.checkRequestOptions(this.resolvePath(effectiveParams), this.buildQueryTrackerOptions(options));
|
|
7081
|
+
const shouldMakeRequest = trackerAllowsRequest;
|
|
7082
|
+
if (shouldMakeRequest) {
|
|
7078
7083
|
return fetchFromAPI();
|
|
7084
|
+
}
|
|
7079
7085
|
return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
|
|
7080
7086
|
if (Array.isArray(dbData) && dbData.length > 0) {
|
|
7081
7087
|
this.setData$(dbData);
|
|
7082
7088
|
return of(dbData);
|
|
7083
7089
|
}
|
|
7084
|
-
|
|
7085
|
-
|
|
7090
|
+
const currentStateData = this.get()?.data;
|
|
7091
|
+
if (Array.isArray(currentStateData) && currentStateData.length > 0) {
|
|
7092
|
+
return of(currentStateData);
|
|
7093
|
+
}
|
|
7094
|
+
if (currentStateData &&
|
|
7095
|
+
!Array.isArray(currentStateData) &&
|
|
7096
|
+
Object.keys(currentStateData).length > 0) {
|
|
7097
|
+
return of(currentStateData);
|
|
7098
|
+
}
|
|
7099
|
+
return of(this.dataType === DataType.ARRAY ? [] : {});
|
|
7086
7100
|
}), catchError((error) => {
|
|
7087
7101
|
const tableName = this.databaseOptions.table;
|
|
7088
7102
|
console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
|
|
@@ -7240,8 +7254,13 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7240
7254
|
if (this.hasDatabase && this.databaseOptions?.table) {
|
|
7241
7255
|
const requestSignature = this.buildRequestSignature('STREAM', requestOptions, effectiveParams);
|
|
7242
7256
|
return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
|
|
7257
|
+
const forceRefresh = !!options?.forceRefresh;
|
|
7243
7258
|
const expires = storeData?.expires || 0;
|
|
7244
7259
|
const hasExpired = expires > 0 && this.utils.hasExpired(expires);
|
|
7260
|
+
if (forceRefresh) {
|
|
7261
|
+
this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
|
|
7262
|
+
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7263
|
+
}
|
|
7245
7264
|
if (hasExpired) {
|
|
7246
7265
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(tap(() => this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature)), switchMap(() => this.httpManagerService.getRequest(requestOptions, effectiveParams)), map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7247
7266
|
}
|
|
@@ -7252,8 +7271,16 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7252
7271
|
if (Array.isArray(dbData) && dbData.length > 0) {
|
|
7253
7272
|
return of({ data: dbData, fromCache: true });
|
|
7254
7273
|
}
|
|
7255
|
-
|
|
7256
|
-
|
|
7274
|
+
const currentStateData = this.get()?.data;
|
|
7275
|
+
if (Array.isArray(currentStateData) && currentStateData.length > 0) {
|
|
7276
|
+
return of({ data: currentStateData, fromCache: true });
|
|
7277
|
+
}
|
|
7278
|
+
if (currentStateData &&
|
|
7279
|
+
!Array.isArray(currentStateData) &&
|
|
7280
|
+
Object.keys(currentStateData).length > 0) {
|
|
7281
|
+
return of({ data: currentStateData, fromCache: true });
|
|
7282
|
+
}
|
|
7283
|
+
return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
|
|
7257
7284
|
}));
|
|
7258
7285
|
}
|
|
7259
7286
|
this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
|
|
@@ -7403,24 +7430,17 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7403
7430
|
});
|
|
7404
7431
|
}
|
|
7405
7432
|
}
|
|
7406
|
-
|
|
7407
|
-
if (!wsOptions) {
|
|
7408
|
-
this.logger.debug('StateStore', 'WSOptions not provided; skipping WebSocket initialization');
|
|
7409
|
-
return;
|
|
7410
|
-
}
|
|
7411
|
-
const wsId = String(wsOptions.id || '').trim();
|
|
7412
|
-
if (wsId !== '') {
|
|
7413
|
-
wsOptions.id = wsId;
|
|
7433
|
+
if (this.apiOptions.ws && this.apiOptions.ws.id !== '') {
|
|
7414
7434
|
// Auto-prefix channel ID for private state manager channels
|
|
7415
7435
|
// This ensures state manager channels are separate from user-defined channels
|
|
7416
|
-
|
|
7417
|
-
this.logger.debug('StateStore', `🔒 Private state channel configured`, { channelId:
|
|
7436
|
+
this.apiOptions.ws.id = this.prefixChannel(this.apiOptions.ws.id, ChannelType.STATE);
|
|
7437
|
+
this.logger.debug('StateStore', `🔒 Private state channel configured`, { channelId: this.apiOptions.ws.id });
|
|
7418
7438
|
// Store our own sessionId for filtering incoming messages
|
|
7419
7439
|
this.ownSessionId = sessionStorage.getItem('WSID') || null;
|
|
7420
7440
|
this.logger.debug('StateStore', `🆔 Stored own sessionId for message filtering`, { sessionId: this.ownSessionId });
|
|
7421
7441
|
this.logger.debug('StateStore', `🔍 WebSocket configuration`, {
|
|
7422
|
-
channelId:
|
|
7423
|
-
wsServer:
|
|
7442
|
+
channelId: this.apiOptions.ws.id,
|
|
7443
|
+
wsServer: this.apiOptions.ws.wsServer,
|
|
7424
7444
|
sessionId: this.ownSessionId,
|
|
7425
7445
|
path: this.apiOptions.path
|
|
7426
7446
|
});
|
|
@@ -7432,15 +7452,13 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7432
7452
|
// initWS is an effect that triggers when setApiRequestOptions is called with ws config
|
|
7433
7453
|
// The effect is already triggered by calling setApiRequestOptions above
|
|
7434
7454
|
}
|
|
7435
|
-
if (
|
|
7436
|
-
this.maxRetries =
|
|
7437
|
-
this.retryDelay = (
|
|
7455
|
+
if (this.apiOptions.ws?.retry) {
|
|
7456
|
+
this.maxRetries = this.apiOptions.ws.retry.times || 3;
|
|
7457
|
+
this.retryDelay = (this.apiOptions.ws.retry.delay && this.apiOptions.ws.retry.delay * 1000) || 5 * 1000;
|
|
7438
7458
|
this.wsNextRetry.next(this.retryDelay);
|
|
7439
7459
|
}
|
|
7440
7460
|
// Validate wsServer before attempting connection
|
|
7441
|
-
|
|
7442
|
-
wsOptions.wsServer = wsServer;
|
|
7443
|
-
if (!wsServer) {
|
|
7461
|
+
if (!this.apiOptions.ws.wsServer || this.apiOptions.ws.wsServer === '') {
|
|
7444
7462
|
this.logger.error('StateStore', 'WSOptions invalid: wsServer is missing or empty');
|
|
7445
7463
|
return;
|
|
7446
7464
|
}
|
|
@@ -7453,9 +7471,9 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7453
7471
|
this.connectionStatusSubscription = this.setupConnectionStatus().subscribe();
|
|
7454
7472
|
// Make initial connection attempt
|
|
7455
7473
|
this.logger.debug('StateStore', '🔄 Initial WebSocket connection attempt...');
|
|
7456
|
-
this.httpManagerService.connect(
|
|
7474
|
+
this.httpManagerService.connect(this.apiOptions.ws, this.apiOptions.ws.jwtToken || '');
|
|
7457
7475
|
// Initialize WS effect to handle messages
|
|
7458
|
-
this.initWS(
|
|
7476
|
+
this.initWS(this.apiOptions.ws);
|
|
7459
7477
|
}
|
|
7460
7478
|
else {
|
|
7461
7479
|
this.logger.warn('StateStore', 'WSOptions invalid Id: empty');
|
|
@@ -7967,13 +7985,10 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7967
7985
|
return options;
|
|
7968
7986
|
}
|
|
7969
7987
|
buildQueryTrackerOptions(options) {
|
|
7970
|
-
|
|
7988
|
+
return {
|
|
7989
|
+
watchParams: Array.isArray(options?.watchParams) ? options.watchParams : [],
|
|
7971
7990
|
watchExpiresAt: options?.watchExpiresAt,
|
|
7972
7991
|
};
|
|
7973
|
-
if (Array.isArray(options?.watchParams)) {
|
|
7974
|
-
result.watchParams = options.watchParams;
|
|
7975
|
-
}
|
|
7976
|
-
return result;
|
|
7977
7992
|
}
|
|
7978
7993
|
normalizeObject(value) {
|
|
7979
7994
|
if (Array.isArray(value)) {
|