http-request-manager 18.13.17 → 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))
|
|
@@ -1276,23 +1192,7 @@ class QueryParamsTrackerService {
|
|
|
1276
1192
|
}, {}));
|
|
1277
1193
|
}
|
|
1278
1194
|
isTrackerState(value) {
|
|
1279
|
-
|
|
1280
|
-
return false;
|
|
1281
|
-
}
|
|
1282
|
-
return Object.keys(value.paths).every((pathKey) => this.isTrackerPathState(value.paths[pathKey]));
|
|
1283
|
-
}
|
|
1284
|
-
isTrackerPathState(value) {
|
|
1285
|
-
if (!this.isPlainObject(value)) {
|
|
1286
|
-
return false;
|
|
1287
|
-
}
|
|
1288
|
-
const hasValidConsumedValues = typeof value.consumedValuesByKey === 'undefined' || this.isPlainObject(value.consumedValuesByKey);
|
|
1289
|
-
const hasValidTrackedAt = typeof value.trackedAt === 'undefined' || typeof value.trackedAt === 'number';
|
|
1290
|
-
const hasValidWatchExpiresAt = typeof value.watchExpiresAt === 'undefined' || typeof value.watchExpiresAt === 'number';
|
|
1291
|
-
const hasValidBaselineQuery = typeof value.baselineQuery === 'undefined' || this.isPlainObject(value.baselineQuery);
|
|
1292
|
-
const hasTrackerMarkers = this.isPlainObject(value.consumedValuesByKey) ||
|
|
1293
|
-
typeof value.trackedAt === 'number' ||
|
|
1294
|
-
this.isPlainObject(value.baselineQuery);
|
|
1295
|
-
return hasValidConsumedValues && hasValidTrackedAt && hasValidWatchExpiresAt && hasValidBaselineQuery && hasTrackerMarkers;
|
|
1195
|
+
return this.isPlainObject(value) && this.isPlainObject(value.paths);
|
|
1296
1196
|
}
|
|
1297
1197
|
isPlainObject(value) {
|
|
1298
1198
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
@@ -5517,87 +5417,6 @@ const storage = {
|
|
|
5517
5417
|
settings: [],
|
|
5518
5418
|
};
|
|
5519
5419
|
class LocalStorageManagerService extends ComponentStore {
|
|
5520
|
-
getStoreSync(storeName) {
|
|
5521
|
-
storeName = storeName.toLowerCase();
|
|
5522
|
-
const data = this.get();
|
|
5523
|
-
const foundStore = data.settings.find(item => item.name === storeName);
|
|
5524
|
-
if (!foundStore) {
|
|
5525
|
-
return null;
|
|
5526
|
-
}
|
|
5527
|
-
const found = foundStore.options?.storage === StorageType.GLOBAL
|
|
5528
|
-
? data.localStores.find(item => item.id === foundStore.id)
|
|
5529
|
-
: data.sessionStores.find(item => item.id === foundStore.id);
|
|
5530
|
-
if (!found || !this.app?.appID) {
|
|
5531
|
-
return null;
|
|
5532
|
-
}
|
|
5533
|
-
const options = SettingOptions.adapt(foundStore.options);
|
|
5534
|
-
let storageData = found.data;
|
|
5535
|
-
if (options.encrypted) {
|
|
5536
|
-
const decryptedData = this.encryption.decrypt(found.data, this.app.appID);
|
|
5537
|
-
if (decryptedData !== null) {
|
|
5538
|
-
storageData = decryptedData;
|
|
5539
|
-
}
|
|
5540
|
-
}
|
|
5541
|
-
try {
|
|
5542
|
-
return this.isString(storageData) ? JSON.parse(storageData) : storageData;
|
|
5543
|
-
}
|
|
5544
|
-
catch {
|
|
5545
|
-
return storageData;
|
|
5546
|
-
}
|
|
5547
|
-
}
|
|
5548
|
-
getPersistedStoreSync(storeName) {
|
|
5549
|
-
storeName = this.validStoreName(String(storeName || ''));
|
|
5550
|
-
if (!storeName || !this.app?.appID) {
|
|
5551
|
-
return null;
|
|
5552
|
-
}
|
|
5553
|
-
const settingsStr = localStorage.getItem(this.storageSettingsName);
|
|
5554
|
-
if (!settingsStr) {
|
|
5555
|
-
return null;
|
|
5556
|
-
}
|
|
5557
|
-
let settings = [];
|
|
5558
|
-
try {
|
|
5559
|
-
const decryptedSettings = this.encryption.decrypt(settingsStr, this.app.appID);
|
|
5560
|
-
settings = decryptedSettings ? JSON.parse(decryptedSettings) : [];
|
|
5561
|
-
}
|
|
5562
|
-
catch {
|
|
5563
|
-
return null;
|
|
5564
|
-
}
|
|
5565
|
-
const foundSetting = settings.find(item => item.name === storeName);
|
|
5566
|
-
if (!foundSetting) {
|
|
5567
|
-
return null;
|
|
5568
|
-
}
|
|
5569
|
-
const rawStores = foundSetting.options?.storage === StorageType.GLOBAL
|
|
5570
|
-
? localStorage.getItem(this.storageName)
|
|
5571
|
-
: sessionStorage.getItem(this.storageName);
|
|
5572
|
-
if (!rawStores) {
|
|
5573
|
-
return null;
|
|
5574
|
-
}
|
|
5575
|
-
let stores = [];
|
|
5576
|
-
try {
|
|
5577
|
-
stores = JSON.parse(rawStores);
|
|
5578
|
-
}
|
|
5579
|
-
catch {
|
|
5580
|
-
return null;
|
|
5581
|
-
}
|
|
5582
|
-
const foundStore = stores.find(item => item.id === foundSetting.id);
|
|
5583
|
-
if (!foundStore) {
|
|
5584
|
-
return null;
|
|
5585
|
-
}
|
|
5586
|
-
const options = SettingOptions.adapt(foundSetting.options);
|
|
5587
|
-
let storageData = foundStore.data;
|
|
5588
|
-
if (options.encrypted) {
|
|
5589
|
-
const decryptedData = this.encryption.decrypt(foundStore.data, this.app.appID);
|
|
5590
|
-
if (decryptedData !== null) {
|
|
5591
|
-
storageData = decryptedData;
|
|
5592
|
-
}
|
|
5593
|
-
}
|
|
5594
|
-
try {
|
|
5595
|
-
return this.isString(storageData) ? JSON.parse(storageData) : storageData;
|
|
5596
|
-
}
|
|
5597
|
-
catch {
|
|
5598
|
-
return storageData;
|
|
5599
|
-
}
|
|
5600
|
-
}
|
|
5601
5420
|
startTimer() {
|
|
5602
5421
|
const timer$ = interval(1000 * 3).pipe(withLatestFrom(this.data$), map(([_, state]) => state), tap((state) => {
|
|
5603
5422
|
const expired = this.expired(state) ? this.expired(state) : [];
|
|
@@ -7418,14 +7237,14 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7418
7237
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7419
7238
|
})).pipe(tap((packet) => {
|
|
7420
7239
|
const res = packet?.data;
|
|
7421
|
-
|
|
7240
|
+
console.log('[DEBUG] Streaming response received:', res);
|
|
7422
7241
|
if (res && res.length > 0) {
|
|
7423
|
-
|
|
7242
|
+
console.log('[DEBUG] Updating state with streaming data:', res);
|
|
7424
7243
|
this.setData$(res);
|
|
7425
7244
|
this.streamedResponse = res;
|
|
7426
7245
|
}
|
|
7427
7246
|
else {
|
|
7428
|
-
|
|
7247
|
+
console.log('[DEBUG] No streaming data or empty array:', res);
|
|
7429
7248
|
}
|
|
7430
7249
|
// Reset pending once we have a response packet (cache or network)
|
|
7431
7250
|
this.httpManagerService.isPending.next(false);
|
|
@@ -7435,33 +7254,33 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7435
7254
|
}
|
|
7436
7255
|
return this.persistStreamDataToDb(packet?.data, options);
|
|
7437
7256
|
}), map((res) => {
|
|
7438
|
-
|
|
7257
|
+
console.log('[DEBUG] Returning data to subscribers:', res);
|
|
7439
7258
|
return res;
|
|
7440
7259
|
}), catchError((error) => {
|
|
7441
|
-
|
|
7260
|
+
console.error('[DEBUG] Streaming error:', error);
|
|
7442
7261
|
this.httpManagerService.isPending.next(false);
|
|
7443
7262
|
return of([]);
|
|
7444
7263
|
}));
|
|
7445
7264
|
}
|
|
7446
7265
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams)
|
|
7447
7266
|
.pipe(tap((res) => {
|
|
7448
|
-
|
|
7267
|
+
console.log('[DEBUG] Streaming response received:', res);
|
|
7449
7268
|
// Always update state with streaming data
|
|
7450
7269
|
if (res && res.length > 0) {
|
|
7451
|
-
|
|
7270
|
+
console.log('[DEBUG] Updating state with streaming data:', res);
|
|
7452
7271
|
this.setData$(res);
|
|
7453
7272
|
this.streamedResponse = res;
|
|
7454
7273
|
}
|
|
7455
7274
|
else {
|
|
7456
|
-
|
|
7275
|
+
console.log('[DEBUG] No streaming data or empty array:', res);
|
|
7457
7276
|
}
|
|
7458
7277
|
// Reset pending once we have a response packet
|
|
7459
7278
|
this.httpManagerService.isPending.next(false);
|
|
7460
7279
|
}), concatMap((res) => this.persistStreamDataToDb(res, options)), map((res) => {
|
|
7461
|
-
|
|
7280
|
+
console.log('[DEBUG] Returning data to subscribers:', res);
|
|
7462
7281
|
return res; // Return the data so subscribers can receive it
|
|
7463
7282
|
}), catchError((error) => {
|
|
7464
|
-
|
|
7283
|
+
console.error('[DEBUG] Streaming error:', error);
|
|
7465
7284
|
this.httpManagerService.isPending.next(false);
|
|
7466
7285
|
return of([]);
|
|
7467
7286
|
}));
|
|
@@ -7826,15 +7645,15 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7826
7645
|
return;
|
|
7827
7646
|
}
|
|
7828
7647
|
// DEBUG: Log what we're sending
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
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
|
+
});
|
|
7838
7657
|
this.httpManagerService.sendMessageInChannel(wsServer, { method, path, user: this.apiOptions.ws.user });
|
|
7839
7658
|
}
|
|
7840
7659
|
else {
|
|
@@ -8090,8 +7909,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8090
7909
|
if (!this.hasDatabase || !this.databaseOptions?.table)
|
|
8091
7910
|
return;
|
|
8092
7911
|
const tableName = this.databaseOptions.table;
|
|
8093
|
-
this.dbManagerService.clearTable(tableName)
|
|
8094
|
-
.subscribe({
|
|
7912
|
+
this.dbManagerService.clearTable(tableName).subscribe({
|
|
8095
7913
|
next: () => {
|
|
8096
7914
|
this.clearRequestCacheMetadata(tableName);
|
|
8097
7915
|
if (this.dataType === DataType.ARRAY) {
|
|
@@ -8106,17 +7924,6 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8106
7924
|
}
|
|
8107
7925
|
});
|
|
8108
7926
|
}
|
|
8109
|
-
clearTable(tableName) {
|
|
8110
|
-
this.dbManagerService.clearTable(tableName)
|
|
8111
|
-
.subscribe({
|
|
8112
|
-
next: () => {
|
|
8113
|
-
this.clearRequestCacheMetadata(tableName);
|
|
8114
|
-
},
|
|
8115
|
-
error: (err) => {
|
|
8116
|
-
console.error(`❌ Error clearing table ${tableName}:`, err);
|
|
8117
|
-
}
|
|
8118
|
-
});
|
|
8119
|
-
}
|
|
8120
7927
|
isEmpty(obj) {
|
|
8121
7928
|
return Object.keys(obj).length === 0;
|
|
8122
7929
|
}
|