http-request-manager 18.13.16 → 18.13.18
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.
|
@@ -876,14 +876,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
876
876
|
}], ctorParameters: () => [] });
|
|
877
877
|
|
|
878
878
|
class PathTrackerStateModel {
|
|
879
|
-
constructor(baselineQuery, consumedValuesByKey = {}, watchExpiresAt
|
|
879
|
+
constructor(baselineQuery, consumedValuesByKey = {}, watchExpiresAt) {
|
|
880
880
|
this.baselineQuery = baselineQuery;
|
|
881
881
|
this.consumedValuesByKey = consumedValuesByKey;
|
|
882
882
|
this.watchExpiresAt = watchExpiresAt;
|
|
883
|
-
this.trackedAt = trackedAt;
|
|
884
883
|
}
|
|
885
884
|
static adapt(item) {
|
|
886
|
-
return new PathTrackerStateModel(item?.baselineQuery, item?.consumedValuesByKey, item?.watchExpiresAt
|
|
885
|
+
return new PathTrackerStateModel(item?.baselineQuery, item?.consumedValuesByKey, item?.watchExpiresAt);
|
|
887
886
|
}
|
|
888
887
|
}
|
|
889
888
|
|
|
@@ -904,15 +903,14 @@ class QueryTrackerStateModel {
|
|
|
904
903
|
const TRACKER_STORE_NAME = 'query_params_tracker';
|
|
905
904
|
const TRACKER_SESSION_INIT_KEY = 'query_params_tracker_initialized';
|
|
906
905
|
const DEFAULT_TRACKER_OPTIONS = SettingOptions.adapt({
|
|
907
|
-
storage: StorageType.
|
|
906
|
+
storage: StorageType.GLOBAL,
|
|
908
907
|
encrypted: false,
|
|
909
|
-
expiresIn: '1d',
|
|
910
908
|
});
|
|
911
909
|
class QueryParamsTrackerService {
|
|
912
910
|
constructor() {
|
|
913
|
-
this.localStorageManager = inject(LocalStorageManagerService);
|
|
914
911
|
this.state = { paths: {} };
|
|
915
912
|
this.stateRestored = false;
|
|
913
|
+
this.localStorageManager = inject(LocalStorageManagerService);
|
|
916
914
|
}
|
|
917
915
|
clearTracking(resetSessionInit = false) {
|
|
918
916
|
this.state = { paths: {} };
|
|
@@ -923,18 +921,12 @@ class QueryParamsTrackerService {
|
|
|
923
921
|
}
|
|
924
922
|
checkRequestOptions(requestOptions = [], options = {}) {
|
|
925
923
|
this.ensureStateRestored();
|
|
926
|
-
this.tryHydrateStateFromPersistedStore();
|
|
927
924
|
const normalized = this.normalizeRequestOptions(requestOptions);
|
|
928
925
|
if (!normalized.pathKey)
|
|
929
926
|
return false;
|
|
930
927
|
this.cleanupExpiredEntries();
|
|
931
928
|
if (!normalized.hasQuery) {
|
|
932
|
-
|
|
933
|
-
if (pathExists) {
|
|
934
|
-
return false;
|
|
935
|
-
}
|
|
936
|
-
const pathState = this.ensurePathState(normalized.pathKey);
|
|
937
|
-
pathState.trackedAt = Math.floor(Date.now() / 1000);
|
|
929
|
+
this.ensurePathState(normalized.pathKey);
|
|
938
930
|
this.persistState();
|
|
939
931
|
return true;
|
|
940
932
|
}
|
|
@@ -945,7 +937,6 @@ class QueryParamsTrackerService {
|
|
|
945
937
|
}
|
|
946
938
|
matchesPath(requestOptions = [], expectedPathOptions = []) {
|
|
947
939
|
this.ensureStateRestored();
|
|
948
|
-
this.tryHydrateStateFromPersistedStore();
|
|
949
940
|
const requestPath = this.normalizeRequestOptions(requestOptions).pathKey;
|
|
950
941
|
const expectedPath = this.normalizeRequestOptions(expectedPathOptions).pathKey;
|
|
951
942
|
return Boolean(requestPath) && requestPath === expectedPath;
|
|
@@ -1057,31 +1048,13 @@ class QueryParamsTrackerService {
|
|
|
1057
1048
|
}
|
|
1058
1049
|
}
|
|
1059
1050
|
normalizePath(pathSegments) {
|
|
1060
|
-
|
|
1061
|
-
.map((segment) => this.extractPathFromSegment(segment))
|
|
1062
|
-
.flatMap((segment) => segment.split('/'))
|
|
1051
|
+
return pathSegments
|
|
1063
1052
|
.map((segment) => String(segment).trim())
|
|
1064
|
-
.filter((segment) => segment.length > 0)
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
return normalizedSegments.join('/');
|
|
1070
|
-
}
|
|
1071
|
-
extractPathFromSegment(segment) {
|
|
1072
|
-
const raw = String(segment).trim();
|
|
1073
|
-
if (!raw) {
|
|
1074
|
-
return '';
|
|
1075
|
-
}
|
|
1076
|
-
try {
|
|
1077
|
-
if (/^https?:\/\//i.test(raw)) {
|
|
1078
|
-
return new URL(raw).pathname;
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
catch {
|
|
1082
|
-
return raw;
|
|
1083
|
-
}
|
|
1084
|
-
return raw;
|
|
1053
|
+
.filter((segment) => segment.length > 0)
|
|
1054
|
+
.join('/')
|
|
1055
|
+
.replace(/([^:]\/+)\/+/g, '$1')
|
|
1056
|
+
.replace(/^\//, '')
|
|
1057
|
+
.replace(/\/$/, '');
|
|
1085
1058
|
}
|
|
1086
1059
|
normalizeParamKey(key) {
|
|
1087
1060
|
return String(key).trim().toLowerCase();
|
|
@@ -1146,8 +1119,7 @@ class QueryParamsTrackerService {
|
|
|
1146
1119
|
}
|
|
1147
1120
|
const hasBaseline = Boolean(pathState.baselineQuery && Object.keys(pathState.baselineQuery).length > 0);
|
|
1148
1121
|
const hasTrackedValues = Object.keys(pathState.consumedValuesByKey).some((key) => (pathState.consumedValuesByKey[key] || []).length > 0);
|
|
1149
|
-
|
|
1150
|
-
if (!hasBaseline && !hasTrackedValues && !isNoQueryTracked) {
|
|
1122
|
+
if (!hasBaseline && !hasTrackedValues) {
|
|
1151
1123
|
delete this.state.paths[pathKey];
|
|
1152
1124
|
}
|
|
1153
1125
|
});
|
|
@@ -1176,20 +1148,14 @@ class QueryParamsTrackerService {
|
|
|
1176
1148
|
if (initialized === '1') {
|
|
1177
1149
|
return;
|
|
1178
1150
|
}
|
|
1151
|
+
this.clearTracking();
|
|
1179
1152
|
sessionStorage.setItem(TRACKER_SESSION_INIT_KEY, '1');
|
|
1180
1153
|
}
|
|
1181
1154
|
restoreState() {
|
|
1182
|
-
this.tryHydrateStateFromPersistedStore();
|
|
1183
|
-
if (Object.keys(this.state.paths).length > 0) {
|
|
1184
|
-
return;
|
|
1185
|
-
}
|
|
1186
1155
|
this.localStorageManager.store$(TRACKER_STORE_NAME)
|
|
1187
1156
|
.pipe(take(1))
|
|
1188
1157
|
.subscribe({
|
|
1189
1158
|
next: (storedState) => {
|
|
1190
|
-
if (Object.keys(this.state.paths).length > 0) {
|
|
1191
|
-
return;
|
|
1192
|
-
}
|
|
1193
1159
|
if (this.isTrackerState(storedState)) {
|
|
1194
1160
|
this.state = QueryTrackerStateModel.adapt(storedState);
|
|
1195
1161
|
this.cleanupExpiredEntries();
|
|
@@ -1198,60 +1164,10 @@ class QueryParamsTrackerService {
|
|
|
1198
1164
|
this.state = { paths: {} };
|
|
1199
1165
|
},
|
|
1200
1166
|
error: () => {
|
|
1201
|
-
|
|
1202
|
-
this.state = { paths: {} };
|
|
1203
|
-
}
|
|
1167
|
+
this.state = { paths: {} };
|
|
1204
1168
|
}
|
|
1205
1169
|
});
|
|
1206
1170
|
}
|
|
1207
|
-
tryHydrateStateFromPersistedStore() {
|
|
1208
|
-
if (Object.keys(this.state.paths).length > 0) {
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
|
-
const syncState = this.localStorageManager.getPersistedStoreSync(TRACKER_STORE_NAME);
|
|
1212
|
-
if (this.isTrackerState(syncState)) {
|
|
1213
|
-
this.state = QueryTrackerStateModel.adapt(syncState);
|
|
1214
|
-
this.cleanupExpiredEntries();
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
|
-
const fallbackState = this.getTrackerStateFromRawStorage();
|
|
1218
|
-
if (!this.isTrackerState(fallbackState)) {
|
|
1219
|
-
return;
|
|
1220
|
-
}
|
|
1221
|
-
this.state = QueryTrackerStateModel.adapt(fallbackState);
|
|
1222
|
-
this.cleanupExpiredEntries();
|
|
1223
|
-
}
|
|
1224
|
-
getTrackerStateFromRawStorage() {
|
|
1225
|
-
const rawSources = [
|
|
1226
|
-
this.safeParseRawStorage(localStorage.getItem('storage')),
|
|
1227
|
-
this.safeParseRawStorage(sessionStorage.getItem('storage')),
|
|
1228
|
-
];
|
|
1229
|
-
for (const source of rawSources) {
|
|
1230
|
-
if (!Array.isArray(source)) {
|
|
1231
|
-
continue;
|
|
1232
|
-
}
|
|
1233
|
-
for (const entry of source) {
|
|
1234
|
-
if (this.isTrackerState(entry?.data)) {
|
|
1235
|
-
return entry.data;
|
|
1236
|
-
}
|
|
1237
|
-
if (this.isTrackerState(entry)) {
|
|
1238
|
-
return entry;
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
return null;
|
|
1243
|
-
}
|
|
1244
|
-
safeParseRawStorage(value) {
|
|
1245
|
-
if (!value) {
|
|
1246
|
-
return null;
|
|
1247
|
-
}
|
|
1248
|
-
try {
|
|
1249
|
-
return JSON.parse(value);
|
|
1250
|
-
}
|
|
1251
|
-
catch {
|
|
1252
|
-
return null;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
1171
|
persistState() {
|
|
1256
1172
|
this.localStorageManager.storeExists$(TRACKER_STORE_NAME)
|
|
1257
1173
|
.pipe(take(1))
|
|
@@ -5501,87 +5417,6 @@ const storage = {
|
|
|
5501
5417
|
settings: [],
|
|
5502
5418
|
};
|
|
5503
5419
|
class LocalStorageManagerService extends ComponentStore {
|
|
5504
|
-
getStoreSync(storeName) {
|
|
5505
|
-
storeName = storeName.toLowerCase();
|
|
5506
|
-
const data = this.get();
|
|
5507
|
-
const foundStore = data.settings.find(item => item.name === storeName);
|
|
5508
|
-
if (!foundStore) {
|
|
5509
|
-
return null;
|
|
5510
|
-
}
|
|
5511
|
-
const found = foundStore.options?.storage === StorageType.GLOBAL
|
|
5512
|
-
? data.localStores.find(item => item.id === foundStore.id)
|
|
5513
|
-
: data.sessionStores.find(item => item.id === foundStore.id);
|
|
5514
|
-
if (!found || !this.app?.appID) {
|
|
5515
|
-
return null;
|
|
5516
|
-
}
|
|
5517
|
-
const options = SettingOptions.adapt(foundStore.options);
|
|
5518
|
-
let storageData = found.data;
|
|
5519
|
-
if (options.encrypted) {
|
|
5520
|
-
const decryptedData = this.encryption.decrypt(found.data, this.app.appID);
|
|
5521
|
-
if (decryptedData !== null) {
|
|
5522
|
-
storageData = decryptedData;
|
|
5523
|
-
}
|
|
5524
|
-
}
|
|
5525
|
-
try {
|
|
5526
|
-
return this.isString(storageData) ? JSON.parse(storageData) : storageData;
|
|
5527
|
-
}
|
|
5528
|
-
catch {
|
|
5529
|
-
return storageData;
|
|
5530
|
-
}
|
|
5531
|
-
}
|
|
5532
|
-
getPersistedStoreSync(storeName) {
|
|
5533
|
-
storeName = this.validStoreName(String(storeName || ''));
|
|
5534
|
-
if (!storeName || !this.app?.appID) {
|
|
5535
|
-
return null;
|
|
5536
|
-
}
|
|
5537
|
-
const settingsStr = localStorage.getItem(this.storageSettingsName);
|
|
5538
|
-
if (!settingsStr) {
|
|
5539
|
-
return null;
|
|
5540
|
-
}
|
|
5541
|
-
let settings = [];
|
|
5542
|
-
try {
|
|
5543
|
-
const decryptedSettings = this.encryption.decrypt(settingsStr, this.app.appID);
|
|
5544
|
-
settings = decryptedSettings ? JSON.parse(decryptedSettings) : [];
|
|
5545
|
-
}
|
|
5546
|
-
catch {
|
|
5547
|
-
return null;
|
|
5548
|
-
}
|
|
5549
|
-
const foundSetting = settings.find(item => item.name === storeName);
|
|
5550
|
-
if (!foundSetting) {
|
|
5551
|
-
return null;
|
|
5552
|
-
}
|
|
5553
|
-
const rawStores = foundSetting.options?.storage === StorageType.GLOBAL
|
|
5554
|
-
? localStorage.getItem(this.storageName)
|
|
5555
|
-
: sessionStorage.getItem(this.storageName);
|
|
5556
|
-
if (!rawStores) {
|
|
5557
|
-
return null;
|
|
5558
|
-
}
|
|
5559
|
-
let stores = [];
|
|
5560
|
-
try {
|
|
5561
|
-
stores = JSON.parse(rawStores);
|
|
5562
|
-
}
|
|
5563
|
-
catch {
|
|
5564
|
-
return null;
|
|
5565
|
-
}
|
|
5566
|
-
const foundStore = stores.find(item => item.id === foundSetting.id);
|
|
5567
|
-
if (!foundStore) {
|
|
5568
|
-
return null;
|
|
5569
|
-
}
|
|
5570
|
-
const options = SettingOptions.adapt(foundSetting.options);
|
|
5571
|
-
let storageData = foundStore.data;
|
|
5572
|
-
if (options.encrypted) {
|
|
5573
|
-
const decryptedData = this.encryption.decrypt(foundStore.data, this.app.appID);
|
|
5574
|
-
if (decryptedData !== null) {
|
|
5575
|
-
storageData = decryptedData;
|
|
5576
|
-
}
|
|
5577
|
-
}
|
|
5578
|
-
try {
|
|
5579
|
-
return this.isString(storageData) ? JSON.parse(storageData) : storageData;
|
|
5580
|
-
}
|
|
5581
|
-
catch {
|
|
5582
|
-
return storageData;
|
|
5583
|
-
}
|
|
5584
|
-
}
|
|
5585
5420
|
startTimer() {
|
|
5586
5421
|
const timer$ = interval(1000 * 3).pipe(withLatestFrom(this.data$), map(([_, state]) => state), tap((state) => {
|
|
5587
5422
|
const expired = this.expired(state) ? this.expired(state) : [];
|
|
@@ -7402,14 +7237,14 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7402
7237
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7403
7238
|
})).pipe(tap((packet) => {
|
|
7404
7239
|
const res = packet?.data;
|
|
7405
|
-
|
|
7240
|
+
console.log('[DEBUG] Streaming response received:', res);
|
|
7406
7241
|
if (res && res.length > 0) {
|
|
7407
|
-
|
|
7242
|
+
console.log('[DEBUG] Updating state with streaming data:', res);
|
|
7408
7243
|
this.setData$(res);
|
|
7409
7244
|
this.streamedResponse = res;
|
|
7410
7245
|
}
|
|
7411
7246
|
else {
|
|
7412
|
-
|
|
7247
|
+
console.log('[DEBUG] No streaming data or empty array:', res);
|
|
7413
7248
|
}
|
|
7414
7249
|
// Reset pending once we have a response packet (cache or network)
|
|
7415
7250
|
this.httpManagerService.isPending.next(false);
|
|
@@ -7419,33 +7254,33 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7419
7254
|
}
|
|
7420
7255
|
return this.persistStreamDataToDb(packet?.data, options);
|
|
7421
7256
|
}), map((res) => {
|
|
7422
|
-
|
|
7257
|
+
console.log('[DEBUG] Returning data to subscribers:', res);
|
|
7423
7258
|
return res;
|
|
7424
7259
|
}), catchError((error) => {
|
|
7425
|
-
|
|
7260
|
+
console.error('[DEBUG] Streaming error:', error);
|
|
7426
7261
|
this.httpManagerService.isPending.next(false);
|
|
7427
7262
|
return of([]);
|
|
7428
7263
|
}));
|
|
7429
7264
|
}
|
|
7430
7265
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams)
|
|
7431
7266
|
.pipe(tap((res) => {
|
|
7432
|
-
|
|
7267
|
+
console.log('[DEBUG] Streaming response received:', res);
|
|
7433
7268
|
// Always update state with streaming data
|
|
7434
7269
|
if (res && res.length > 0) {
|
|
7435
|
-
|
|
7270
|
+
console.log('[DEBUG] Updating state with streaming data:', res);
|
|
7436
7271
|
this.setData$(res);
|
|
7437
7272
|
this.streamedResponse = res;
|
|
7438
7273
|
}
|
|
7439
7274
|
else {
|
|
7440
|
-
|
|
7275
|
+
console.log('[DEBUG] No streaming data or empty array:', res);
|
|
7441
7276
|
}
|
|
7442
7277
|
// Reset pending once we have a response packet
|
|
7443
7278
|
this.httpManagerService.isPending.next(false);
|
|
7444
7279
|
}), concatMap((res) => this.persistStreamDataToDb(res, options)), map((res) => {
|
|
7445
|
-
|
|
7280
|
+
console.log('[DEBUG] Returning data to subscribers:', res);
|
|
7446
7281
|
return res; // Return the data so subscribers can receive it
|
|
7447
7282
|
}), catchError((error) => {
|
|
7448
|
-
|
|
7283
|
+
console.error('[DEBUG] Streaming error:', error);
|
|
7449
7284
|
this.httpManagerService.isPending.next(false);
|
|
7450
7285
|
return of([]);
|
|
7451
7286
|
}));
|
|
@@ -7810,15 +7645,15 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7810
7645
|
return;
|
|
7811
7646
|
}
|
|
7812
7647
|
// DEBUG: Log what we're sending
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7648
|
+
console.log('🔍 [DEBUG] sendWsCommunication called:', {
|
|
7649
|
+
wsServer,
|
|
7650
|
+
wsServerType: typeof wsServer,
|
|
7651
|
+
wsServerEmpty: wsServer === '' || wsServer === null || wsServer === undefined,
|
|
7652
|
+
method,
|
|
7653
|
+
path,
|
|
7654
|
+
user: this.apiOptions.ws.user,
|
|
7655
|
+
fullPayload: { method, path, user: this.apiOptions.ws.user }
|
|
7656
|
+
});
|
|
7822
7657
|
this.httpManagerService.sendMessageInChannel(wsServer, { method, path, user: this.apiOptions.ws.user });
|
|
7823
7658
|
}
|
|
7824
7659
|
else {
|
|
@@ -8074,8 +7909,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8074
7909
|
if (!this.hasDatabase || !this.databaseOptions?.table)
|
|
8075
7910
|
return;
|
|
8076
7911
|
const tableName = this.databaseOptions.table;
|
|
8077
|
-
this.dbManagerService.clearTable(tableName)
|
|
8078
|
-
.subscribe({
|
|
7912
|
+
this.dbManagerService.clearTable(tableName).subscribe({
|
|
8079
7913
|
next: () => {
|
|
8080
7914
|
this.clearRequestCacheMetadata(tableName);
|
|
8081
7915
|
if (this.dataType === DataType.ARRAY) {
|
|
@@ -8090,17 +7924,6 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8090
7924
|
}
|
|
8091
7925
|
});
|
|
8092
7926
|
}
|
|
8093
|
-
clearTable(tableName) {
|
|
8094
|
-
this.dbManagerService.clearTable(tableName)
|
|
8095
|
-
.subscribe({
|
|
8096
|
-
next: () => {
|
|
8097
|
-
this.clearRequestCacheMetadata(tableName);
|
|
8098
|
-
},
|
|
8099
|
-
error: (err) => {
|
|
8100
|
-
console.error(`❌ Error clearing table ${tableName}:`, err);
|
|
8101
|
-
}
|
|
8102
|
-
});
|
|
8103
|
-
}
|
|
8104
7927
|
isEmpty(obj) {
|
|
8105
7928
|
return Object.keys(obj).length === 0;
|
|
8106
7929
|
}
|