http-request-manager 18.13.25 → 18.13.27

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
- 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
- }
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,28 @@ 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 shouldMakeRequest = this.queryParamsTrackerService.checkRequestOptions(this.resolvePath(effectiveParams), this.buildQueryTrackerOptions(options));
7077
- if (shouldMakeRequest)
7078
- return fetchFromAPI();
7080
+ const hasTrackerConfig = Array.isArray(options?.watchParams) && options.watchParams.length > 0;
7081
+ if (hasTrackerConfig) {
7082
+ const trackerAllowsRequest = this.queryParamsTrackerService.checkRequestOptions(this.resolvePath(effectiveParams), this.buildQueryTrackerOptions(options));
7083
+ if (trackerAllowsRequest) {
7084
+ return fetchFromAPI();
7085
+ }
7086
+ }
7079
7087
  return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7080
7088
  if (Array.isArray(dbData) && dbData.length > 0) {
7081
7089
  this.setData$(dbData);
7082
7090
  return of(dbData);
7083
7091
  }
7084
- // DB empty → fall back to API
7085
- return fetchFromAPI();
7092
+ const currentStateData = this.get()?.data;
7093
+ if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7094
+ return of(currentStateData);
7095
+ }
7096
+ if (currentStateData &&
7097
+ !Array.isArray(currentStateData) &&
7098
+ Object.keys(currentStateData).length > 0) {
7099
+ return of(currentStateData);
7100
+ }
7101
+ return of(this.dataType === DataType.ARRAY ? [] : {});
7086
7102
  }), catchError((error) => {
7087
7103
  const tableName = this.databaseOptions.table;
7088
7104
  console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
@@ -7240,21 +7256,36 @@ class HTTPManagerStateService extends ComponentStore {
7240
7256
  if (this.hasDatabase && this.databaseOptions?.table) {
7241
7257
  const requestSignature = this.buildRequestSignature('STREAM', requestOptions, effectiveParams);
7242
7258
  return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
7259
+ const forceRefresh = !!options?.forceRefresh;
7243
7260
  const expires = storeData?.expires || 0;
7244
7261
  const hasExpired = expires > 0 && this.utils.hasExpired(expires);
7262
+ if (forceRefresh) {
7263
+ this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
7264
+ return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
7265
+ }
7245
7266
  if (hasExpired) {
7246
7267
  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
7268
  }
7248
- const trackerAllowsRequest = this.queryParamsTrackerService.checkRequestOptions(this.resolvePath(effectiveParams), this.buildQueryTrackerOptions(options));
7249
- const shouldMakeRequest = trackerAllowsRequest;
7250
- if (!shouldMakeRequest) {
7251
- return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7252
- if (Array.isArray(dbData) && dbData.length > 0) {
7253
- return of({ data: dbData, fromCache: true });
7254
- }
7255
- // DB empty → fall back to API
7256
- return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
7257
- }));
7269
+ const hasTrackerConfig = Array.isArray(options?.watchParams) && options.watchParams.length > 0;
7270
+ if (hasTrackerConfig) {
7271
+ const trackerAllowsRequest = this.queryParamsTrackerService.checkRequestOptions(this.resolvePath(effectiveParams), this.buildQueryTrackerOptions(options));
7272
+ if (!trackerAllowsRequest) {
7273
+ return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7274
+ if (Array.isArray(dbData) && dbData.length > 0) {
7275
+ return of({ data: dbData, fromCache: true });
7276
+ }
7277
+ const currentStateData = this.get()?.data;
7278
+ if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7279
+ return of({ data: currentStateData, fromCache: true });
7280
+ }
7281
+ if (currentStateData &&
7282
+ !Array.isArray(currentStateData) &&
7283
+ Object.keys(currentStateData).length > 0) {
7284
+ return of({ data: currentStateData, fromCache: true });
7285
+ }
7286
+ return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
7287
+ }));
7288
+ }
7258
7289
  }
7259
7290
  this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
7260
7291
  return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
@@ -7403,24 +7434,17 @@ class HTTPManagerStateService extends ComponentStore {
7403
7434
  });
7404
7435
  }
7405
7436
  }
7406
- const wsOptions = this.apiOptions.ws;
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;
7437
+ if (this.apiOptions.ws && this.apiOptions.ws.id !== '') {
7414
7438
  // Auto-prefix channel ID for private state manager channels
7415
7439
  // This ensures state manager channels are separate from user-defined channels
7416
- wsOptions.id = this.prefixChannel(wsOptions.id, ChannelType.STATE);
7417
- this.logger.debug('StateStore', `🔒 Private state channel configured`, { channelId: wsOptions.id });
7440
+ this.apiOptions.ws.id = this.prefixChannel(this.apiOptions.ws.id, ChannelType.STATE);
7441
+ this.logger.debug('StateStore', `🔒 Private state channel configured`, { channelId: this.apiOptions.ws.id });
7418
7442
  // Store our own sessionId for filtering incoming messages
7419
7443
  this.ownSessionId = sessionStorage.getItem('WSID') || null;
7420
7444
  this.logger.debug('StateStore', `🆔 Stored own sessionId for message filtering`, { sessionId: this.ownSessionId });
7421
7445
  this.logger.debug('StateStore', `🔍 WebSocket configuration`, {
7422
- channelId: wsOptions.id,
7423
- wsServer: wsOptions.wsServer,
7446
+ channelId: this.apiOptions.ws.id,
7447
+ wsServer: this.apiOptions.ws.wsServer,
7424
7448
  sessionId: this.ownSessionId,
7425
7449
  path: this.apiOptions.path
7426
7450
  });
@@ -7432,15 +7456,13 @@ class HTTPManagerStateService extends ComponentStore {
7432
7456
  // initWS is an effect that triggers when setApiRequestOptions is called with ws config
7433
7457
  // The effect is already triggered by calling setApiRequestOptions above
7434
7458
  }
7435
- if (wsOptions.retry) {
7436
- this.maxRetries = wsOptions.retry.times || 3;
7437
- this.retryDelay = (wsOptions.retry.delay && wsOptions.retry.delay * 1000) || 5 * 1000;
7459
+ if (this.apiOptions.ws?.retry) {
7460
+ this.maxRetries = this.apiOptions.ws.retry.times || 3;
7461
+ this.retryDelay = (this.apiOptions.ws.retry.delay && this.apiOptions.ws.retry.delay * 1000) || 5 * 1000;
7438
7462
  this.wsNextRetry.next(this.retryDelay);
7439
7463
  }
7440
7464
  // Validate wsServer before attempting connection
7441
- const wsServer = String(wsOptions.wsServer || '').trim();
7442
- wsOptions.wsServer = wsServer;
7443
- if (!wsServer) {
7465
+ if (!this.apiOptions.ws.wsServer || this.apiOptions.ws.wsServer === '') {
7444
7466
  this.logger.error('StateStore', 'WSOptions invalid: wsServer is missing or empty');
7445
7467
  return;
7446
7468
  }
@@ -7453,9 +7475,9 @@ class HTTPManagerStateService extends ComponentStore {
7453
7475
  this.connectionStatusSubscription = this.setupConnectionStatus().subscribe();
7454
7476
  // Make initial connection attempt
7455
7477
  this.logger.debug('StateStore', '🔄 Initial WebSocket connection attempt...');
7456
- this.httpManagerService.connect(wsOptions, wsOptions.jwtToken || '');
7478
+ this.httpManagerService.connect(this.apiOptions.ws, this.apiOptions.ws.jwtToken || '');
7457
7479
  // Initialize WS effect to handle messages
7458
- this.initWS(wsOptions);
7480
+ this.initWS(this.apiOptions.ws);
7459
7481
  }
7460
7482
  else {
7461
7483
  this.logger.warn('StateStore', 'WSOptions invalid Id: empty');
@@ -7967,13 +7989,10 @@ class HTTPManagerStateService extends ComponentStore {
7967
7989
  return options;
7968
7990
  }
7969
7991
  buildQueryTrackerOptions(options) {
7970
- const result = {
7992
+ return {
7993
+ watchParams: Array.isArray(options?.watchParams) ? options.watchParams : [],
7971
7994
  watchExpiresAt: options?.watchExpiresAt,
7972
7995
  };
7973
- if (Array.isArray(options?.watchParams)) {
7974
- result.watchParams = options.watchParams;
7975
- }
7976
- return result;
7977
7996
  }
7978
7997
  normalizeObject(value) {
7979
7998
  if (Array.isArray(value)) {