http-request-manager 18.15.6 → 18.15.8
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.
|
@@ -1933,8 +1933,8 @@ class WebSocketManagerService {
|
|
|
1933
1933
|
WebSocketManagerService.socket.onmessage = (event) => {
|
|
1934
1934
|
try {
|
|
1935
1935
|
const data = JSON.parse(event.data);
|
|
1936
|
-
if (data.error && data.error === 'JWT_INVALID') {
|
|
1937
|
-
console.error(
|
|
1936
|
+
if (data.error && (data.error === 'JWT_INVALID' || data.error === 'AUTH_BLOCKED')) {
|
|
1937
|
+
console.error(`🚫 ${data.error}: ${data.message || 'Authentication error'}`);
|
|
1938
1938
|
WebSocketManagerService.jwtInvalidClose = true;
|
|
1939
1939
|
WebSocketManagerService.messages.next(data);
|
|
1940
1940
|
WebSocketManagerService.connectionStatus.next(false);
|
|
@@ -6241,27 +6241,27 @@ class DatabaseManagerService extends DbService {
|
|
|
6241
6241
|
});
|
|
6242
6242
|
const writeRecords = () => from(this.DBOpened()).pipe(switchMap((opened) => {
|
|
6243
6243
|
if (!opened) {
|
|
6244
|
-
console.error(`createTableRecords: DB not open. Cannot write to '${tableName}'.`);
|
|
6244
|
+
// console.error(`createTableRecords: DB not open. Cannot write to '${tableName}'.`);
|
|
6245
6245
|
return EMPTY;
|
|
6246
6246
|
}
|
|
6247
6247
|
const tableInstance = this.getTable(tableName);
|
|
6248
6248
|
if (!tableInstance) {
|
|
6249
|
-
console.error(`createTableRecords: Table '${tableName}' does not exist in DB version ${this.verno}. Available:`, this.tables.map(t => t.name));
|
|
6249
|
+
// console.error(`createTableRecords: Table '${tableName}' does not exist in DB version ${this.verno}. Available:`, this.tables.map(t => t.name));
|
|
6250
6250
|
return EMPTY;
|
|
6251
6251
|
}
|
|
6252
|
-
console.log(`createTableRecords: Bulk putting ${insertRecords.length} records into ${tableName}`);
|
|
6252
|
+
// console.log(`createTableRecords: Bulk putting ${insertRecords.length} records into ${tableName}`);
|
|
6253
6253
|
return from(tableInstance.bulkPut(insertRecords)).pipe(map(() => insertRecords));
|
|
6254
6254
|
}));
|
|
6255
6255
|
const recreateMissingTableAndRetry = () => {
|
|
6256
6256
|
const inferredSchema = this.inferSchemaFromRecords(insertRecords);
|
|
6257
6257
|
if (!inferredSchema) {
|
|
6258
|
-
console.warn(`createTableRecords: Could not infer schema for '${tableName}'. Retrying after DB reopen.`);
|
|
6258
|
+
// console.warn(`createTableRecords: Could not infer schema for '${tableName}'. Retrying after DB reopen.`);
|
|
6259
6259
|
return from(this.createNewDatabase()).pipe(switchMap(() => writeRecords()));
|
|
6260
6260
|
}
|
|
6261
6261
|
const tableDef = TableSchemaDef.adapt({ table: tableName, schema: inferredSchema });
|
|
6262
6262
|
return this.createDatabaseTable(tableDef).pipe(switchMap((created) => {
|
|
6263
6263
|
if (!created) {
|
|
6264
|
-
console.warn(`createTableRecords: Failed to recreate table '${tableName}' from inferred schema. Retrying after DB reopen.`);
|
|
6264
|
+
// console.warn(`createTableRecords: Failed to recreate table '${tableName}' from inferred schema. Retrying after DB reopen.`);
|
|
6265
6265
|
return from(this.createNewDatabase()).pipe(switchMap(() => writeRecords()));
|
|
6266
6266
|
}
|
|
6267
6267
|
return writeRecords();
|
|
@@ -6271,7 +6271,7 @@ class DatabaseManagerService extends DbService {
|
|
|
6271
6271
|
if (!this.isMissingObjectStoreError(error)) {
|
|
6272
6272
|
throw error;
|
|
6273
6273
|
}
|
|
6274
|
-
console.warn(`createTableRecords: Missing object store for '${tableName}'. Recreating table and retrying once...`, error);
|
|
6274
|
+
// console.warn(`createTableRecords: Missing object store for '${tableName}'. Recreating table and retrying once...`, error);
|
|
6275
6275
|
return recreateMissingTableAndRetry().pipe(catchError((retryError) => {
|
|
6276
6276
|
console.error(`createTableRecords: Retry failed for '${tableName}'`, retryError);
|
|
6277
6277
|
throw retryError;
|
|
@@ -6814,6 +6814,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
6814
6814
|
'if-none-match'
|
|
6815
6815
|
]);
|
|
6816
6816
|
this.requestSignatureCache = {};
|
|
6817
|
+
this.inFlightRequestSignatures = new Set();
|
|
6817
6818
|
this._requestCachePaths = new Map();
|
|
6818
6819
|
this.wsRetryAttempts = new BehaviorSubject(0);
|
|
6819
6820
|
this.wsRetryAttempts$ = this.wsRetryAttempts.asObservable();
|
|
@@ -7207,6 +7208,18 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7207
7208
|
const fetchFromAPI = () => {
|
|
7208
7209
|
if (this.hasDatabase && this.databaseOptions?.table) {
|
|
7209
7210
|
this.setCachedRequestSignature(this.databaseOptions.table, 'GET', requestSignature);
|
|
7211
|
+
if (!this.tryBeginInFlightRequest(requestSignature)) {
|
|
7212
|
+
const currentStateData = this.get()?.data;
|
|
7213
|
+
if (Array.isArray(currentStateData) && currentStateData.length > 0) {
|
|
7214
|
+
return of(currentStateData);
|
|
7215
|
+
}
|
|
7216
|
+
if (currentStateData &&
|
|
7217
|
+
!Array.isArray(currentStateData) &&
|
|
7218
|
+
Object.keys(currentStateData).length > 0) {
|
|
7219
|
+
return of(currentStateData);
|
|
7220
|
+
}
|
|
7221
|
+
return of(this.dataType === DataType.ARRAY ? [] : {});
|
|
7222
|
+
}
|
|
7210
7223
|
}
|
|
7211
7224
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(tap((data) => {
|
|
7212
7225
|
// Extract array from paginated response if needed
|
|
@@ -7245,6 +7258,10 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7245
7258
|
}));
|
|
7246
7259
|
}
|
|
7247
7260
|
return of(data);
|
|
7261
|
+
}), finalize(() => {
|
|
7262
|
+
if (this.hasDatabase && this.databaseOptions?.table) {
|
|
7263
|
+
this.endInFlightRequest(requestSignature);
|
|
7264
|
+
}
|
|
7248
7265
|
}));
|
|
7249
7266
|
};
|
|
7250
7267
|
console.log('[DB STORAGE] Checking database storage:', {
|
|
@@ -7487,23 +7504,38 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7487
7504
|
// console.log('[DEBUG] Making streaming request:', requestOptions)
|
|
7488
7505
|
if (this.hasDatabase && this.databaseOptions?.table) {
|
|
7489
7506
|
const requestSignature = this.buildRequestSignature('STREAM', requestOptions, effectiveParams);
|
|
7507
|
+
const fetchStreamFromAPI = () => {
|
|
7508
|
+
if (!this.tryBeginInFlightRequest(requestSignature)) {
|
|
7509
|
+
const currentStateData = this.get()?.data;
|
|
7510
|
+
if (Array.isArray(currentStateData) && currentStateData.length > 0) {
|
|
7511
|
+
return of({ data: currentStateData, fromCache: true });
|
|
7512
|
+
}
|
|
7513
|
+
if (currentStateData &&
|
|
7514
|
+
!Array.isArray(currentStateData) &&
|
|
7515
|
+
Object.keys(currentStateData).length > 0) {
|
|
7516
|
+
return of({ data: currentStateData, fromCache: true });
|
|
7517
|
+
}
|
|
7518
|
+
return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
|
|
7519
|
+
}
|
|
7520
|
+
this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
|
|
7521
|
+
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })), finalize(() => this.endInFlightRequest(requestSignature)));
|
|
7522
|
+
};
|
|
7490
7523
|
return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
|
|
7491
7524
|
const forceRefresh = !!options?.forceRefresh;
|
|
7492
7525
|
const expires = storeData?.expires || 0;
|
|
7493
7526
|
const hasExpired = expires > 0 && this.utils.hasExpired(expires);
|
|
7494
7527
|
if (forceRefresh) {
|
|
7495
|
-
|
|
7496
|
-
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7528
|
+
return fetchStreamFromAPI();
|
|
7497
7529
|
}
|
|
7498
7530
|
if (hasExpired) {
|
|
7499
|
-
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(
|
|
7531
|
+
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => fetchStreamFromAPI()));
|
|
7500
7532
|
}
|
|
7501
7533
|
const storedSchemaSignature = this.getStoredSchemaSignature(storeData);
|
|
7502
7534
|
const expectedSchema = this.buildSchemaFromAdapter();
|
|
7503
7535
|
const expectedSchemaSignature = this.buildSchemaSignature(expectedSchema);
|
|
7504
7536
|
if (storedSchemaSignature && storedSchemaSignature !== expectedSchemaSignature) {
|
|
7505
7537
|
const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
|
|
7506
|
-
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)),
|
|
7538
|
+
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchStreamFromAPI()));
|
|
7507
7539
|
}
|
|
7508
7540
|
const trackerAllowsRequest = this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData);
|
|
7509
7541
|
if (!trackerAllowsRequest) {
|
|
@@ -7523,8 +7555,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7523
7555
|
return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
|
|
7524
7556
|
}));
|
|
7525
7557
|
}
|
|
7526
|
-
|
|
7527
|
-
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7558
|
+
return fetchStreamFromAPI();
|
|
7528
7559
|
})).pipe(tap((packet) => {
|
|
7529
7560
|
const res = packet?.data;
|
|
7530
7561
|
// console.log('[DEBUG] Streaming response received:', res)
|
|
@@ -8285,6 +8316,16 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8285
8316
|
[type]: signature,
|
|
8286
8317
|
};
|
|
8287
8318
|
}
|
|
8319
|
+
tryBeginInFlightRequest(signature) {
|
|
8320
|
+
if (this.inFlightRequestSignatures.has(signature)) {
|
|
8321
|
+
return false;
|
|
8322
|
+
}
|
|
8323
|
+
this.inFlightRequestSignatures.add(signature);
|
|
8324
|
+
return true;
|
|
8325
|
+
}
|
|
8326
|
+
endInFlightRequest(signature) {
|
|
8327
|
+
this.inFlightRequestSignatures.delete(signature);
|
|
8328
|
+
}
|
|
8288
8329
|
getRequestCacheMetadata(storeData, type) {
|
|
8289
8330
|
return storeData?.requestCache?.[type] || null;
|
|
8290
8331
|
}
|