http-request-manager 15.0.9 → 15.0.11
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.
- package/esm2022/lib/services/local-storage-manager-service/local-storage-manager.service.mjs +1 -1
- package/esm2022/lib/services/local-storage-manager-service/models/setting-options.model.mjs +2 -2
- package/esm2022/lib/services/utils/encryption/asymmetrical-encryption.service.mjs +1 -1
- package/esm2022/lib/services/utils/encryption/symmetrical-encryption.service.mjs +27 -163
- package/esm2022/lib/services/utils/object-merger.service.mjs +5 -5
- package/fesm2022/http-request-manager.mjs +31 -167
- package/fesm2022/http-request-manager.mjs.map +1 -1
- package/http-request-manager-15.0.11.tgz +0 -0
- package/lib/services/utils/encryption/symmetrical-encryption.service.d.ts +1 -12
- package/package.json +4 -2
- package/http-request-manager-15.0.9.tgz +0 -0
|
@@ -8,11 +8,11 @@ export class ObjectMergerService {
|
|
|
8
8
|
const value = options[key];
|
|
9
9
|
if (value !== null &&
|
|
10
10
|
value !== undefined &&
|
|
11
|
-
!(typeof value === 'number')
|
|
12
|
-
!(typeof value === 'boolean')
|
|
11
|
+
!(typeof value === 'number') ||
|
|
12
|
+
!(typeof value === 'boolean') ||
|
|
13
13
|
!(this.isNonEmptyString(value)) &&
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
!(Array.isArray(value) && value.length === 0) &&
|
|
15
|
+
!(typeof value === 'object' && !Array.isArray(value))) {
|
|
16
16
|
merged[key] = value;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -31,4 +31,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
31
31
|
providedIn: 'root'
|
|
32
32
|
}]
|
|
33
33
|
}] });
|
|
34
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
34
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2JqZWN0LW1lcmdlci5zZXJ2aWNlLmpzIiwic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AhPT0gbnVsbCAmJlxuICAgICAgICAgIHZhbHVlICE9PSB1bmRlZmluZWQgJiZcbiAgICAgICAgICAhKHR5cGVvZiB2YWx1ZSA9PT0gJ251bWJlcicpIHx8XG4gICAgICAgICAgISh0eXBlb2YgdmFsdWUgPT09ICdib29sZWFuJykgfHxcbiAgICAgICAgICAhKHRoaXMuaXNOb25FbXB0eVN0cmluZyh2YWx1ZSkpICYmXG4gICAgICAgICAgIShBcnJheS5pc0FycmF5KHZhbHVlKSAmJiB2YWx1ZS5sZW5ndGggPT09IDApICYmXG4gICAgICAgICAgISh0eXBlb2YgdmFsdWUgPT09ICdvYmplY3QnICYmICFBcnJheS5pc0FycmF5KHZhbHVlKSlcbiAgICAgICAgKSB7XG4gICAgICAgICAgKG1lcmdlZCBhcyBhbnkpW2tleV0gPSB2YWx1ZVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICB9XG4gICAgcmV0dXJuIG1lcmdlZDtcbiAgfVxuXG4gIGlzTm9uRW1wdHlTdHJpbmcodmFsdWU6IHVua25vd24pOiB2YWx1ZSBpcyBzdHJpbmcge1xuICAgIHJldHVybiB0eXBlb2YgdmFsdWUgPT09ICdzdHJpbmcnICYmIHZhbHVlLmxlbmd0aCA9PT0gMDtcbiAgfVxuXG59XG4iXX0=
|
|
@@ -3,6 +3,7 @@ import { inject, Injectable, APP_ID, Inject, InjectionToken, Injector, Optional,
|
|
|
3
3
|
import { ComponentStore } from '@ngrx/component-store';
|
|
4
4
|
import { map, catchError, filter, finalize, takeWhile, retry, startWith, tap, mergeMap, takeUntil, withLatestFrom, switchMap, concatMap, scan, distinctUntilChanged } from 'rxjs/operators';
|
|
5
5
|
import { HttpClient, HttpHeaders, HttpEventType, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
6
|
+
import * as CryptoJS from 'crypto-js';
|
|
6
7
|
import { from, BehaviorSubject, EMPTY, throwError, defer, interval, timer, Subject, of, Subscription, catchError as catchError$1 } from 'rxjs';
|
|
7
8
|
import { ToastMessageDisplayService, ToastDisplay, ToastColors, ToastMessageDisplayModule } from 'toast-message-display';
|
|
8
9
|
import * as i1 from '@ngx-translate/core';
|
|
@@ -57,7 +58,7 @@ class SettingOptions {
|
|
|
57
58
|
this.encrypted = encrypted;
|
|
58
59
|
}
|
|
59
60
|
static adapt(item) {
|
|
60
|
-
return new SettingOptions((item?.storage) ? item.storage : StorageType.GLOBAL, (item?.expires) ? item.expires : 0, (item?.expiresIn) ? item.expiresIn : '', (item?.encrypted) ? item
|
|
61
|
+
return new SettingOptions((item?.storage) ? item.storage : StorageType.GLOBAL, (item?.expires) ? item.expires : 0, (item?.expiresIn) ? item.expiresIn : '', (item?.encrypted) ? item.encrypted : false);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -333,193 +334,56 @@ class SymmetricalEncryptionService {
|
|
|
333
334
|
generateCipherKey() {
|
|
334
335
|
return (RandomSignature().toString() + RandomSignature().toString()).substring(0, 8);
|
|
335
336
|
}
|
|
336
|
-
// Synchronous encrypt method to maintain compatibility
|
|
337
337
|
encrypt(str, key = this.appID) {
|
|
338
338
|
if (!str || key === '')
|
|
339
339
|
return '';
|
|
340
|
+
let _key = CryptoJS.enc.Utf8.parse(key);
|
|
341
|
+
let _iv = CryptoJS.enc.Utf8.parse(key);
|
|
340
342
|
try {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
// Convert encrypted data to base64 string
|
|
349
|
-
return this.arrayBufferToBase64(encrypted);
|
|
343
|
+
const encrypted = CryptoJS.AES.encrypt(JSON.stringify(str), _key, {
|
|
344
|
+
keySize: 16,
|
|
345
|
+
iv: _iv,
|
|
346
|
+
mode: CryptoJS.mode.ECB,
|
|
347
|
+
padding: CryptoJS.pad.Pkcs7
|
|
348
|
+
});
|
|
349
|
+
return encrypted.toString();
|
|
350
350
|
}
|
|
351
351
|
catch (error) {
|
|
352
352
|
console.log(error);
|
|
353
|
-
return '';
|
|
354
353
|
}
|
|
354
|
+
return;
|
|
355
355
|
}
|
|
356
|
-
// Synchronous decrypt method to maintain compatibility
|
|
357
356
|
decrypt(str, key = this.appID) {
|
|
358
357
|
if (!str || key === '')
|
|
359
|
-
return
|
|
358
|
+
return;
|
|
359
|
+
let _key = CryptoJS.enc.Utf8.parse(key);
|
|
360
|
+
let _iv = CryptoJS.enc.Utf8.parse(key);
|
|
360
361
|
try {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// Convert decrypted data to string
|
|
368
|
-
return new TextDecoder().decode(decryptedBuffer);
|
|
362
|
+
return CryptoJS.AES.decrypt(str, _key, {
|
|
363
|
+
keySize: 16,
|
|
364
|
+
iv: _iv,
|
|
365
|
+
mode: CryptoJS.mode.ECB,
|
|
366
|
+
padding: CryptoJS.pad.Pkcs7
|
|
367
|
+
}).toString(CryptoJS.enc.Utf8);
|
|
369
368
|
}
|
|
370
369
|
catch (error) {
|
|
371
370
|
console.log(error);
|
|
372
|
-
return undefined;
|
|
373
371
|
}
|
|
372
|
+
return;
|
|
374
373
|
}
|
|
375
374
|
createSignature(url, len = 16) {
|
|
376
|
-
const
|
|
377
|
-
return
|
|
375
|
+
const sig = CryptoJS.SHA256(url).toString(CryptoJS.enc.Hex);
|
|
376
|
+
return sig.substring(0, len).toUpperCase();
|
|
378
377
|
}
|
|
379
378
|
normalizeURL(url) {
|
|
380
379
|
const normalizedURL = url.replace(/(https?:\/\/)?(www\.)?/, '').replace(/\/+$/, '');
|
|
381
380
|
return normalizedURL;
|
|
382
381
|
}
|
|
383
382
|
generateSignature(url) {
|
|
384
|
-
return this.generateSignatureSync(url);
|
|
385
|
-
}
|
|
386
|
-
// Helper methods
|
|
387
|
-
generateSignatureSync(url) {
|
|
388
383
|
const normalizedURL = this.normalizeURL(url);
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
// Create a hash using the SubtleCrypto interface if available, otherwise fallback
|
|
393
|
-
let hashArray;
|
|
394
|
-
try {
|
|
395
|
-
// Create a synchronous hash
|
|
396
|
-
hashArray = this.sha256Sync(data);
|
|
397
|
-
}
|
|
398
|
-
catch (error) {
|
|
399
|
-
console.error('Sync hashing failed, using fallback', error);
|
|
400
|
-
// Simple fallback hash (less secure)
|
|
401
|
-
hashArray = this.simpleHash(data);
|
|
402
|
-
}
|
|
403
|
-
return Array.from(hashArray)
|
|
404
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
405
|
-
.join('');
|
|
406
|
-
}
|
|
407
|
-
// Synchronous SHA-256 implementation
|
|
408
|
-
sha256Sync(data) {
|
|
409
|
-
// This is a simplified version for compatibility
|
|
410
|
-
// It's not as secure as the Web Crypto API but maintains the synchronous API
|
|
411
|
-
const result = new Uint8Array(32); // 256 bits = 32 bytes
|
|
412
|
-
// Simple hash function (for demonstration - not cryptographically strong)
|
|
413
|
-
let h = 0x12345678;
|
|
414
|
-
for (let i = 0; i < data.length; i++) {
|
|
415
|
-
h = ((h << 5) - h) + data[i];
|
|
416
|
-
h |= 0; // Convert to 32bit integer
|
|
417
|
-
}
|
|
418
|
-
// Fill the result with derived values
|
|
419
|
-
for (let i = 0; i < 32; i++) {
|
|
420
|
-
result[i] = ((h >> (i % 4 * 8)) & 0xFF);
|
|
421
|
-
h = Math.imul(h, 2654435761); // Prime number multiplication
|
|
422
|
-
}
|
|
423
|
-
return result;
|
|
424
|
-
}
|
|
425
|
-
// Simple hash function
|
|
426
|
-
simpleHash(data) {
|
|
427
|
-
const result = new Uint8Array(32);
|
|
428
|
-
let h1 = 0x2fd4e1c6;
|
|
429
|
-
let h2 = 0x7b23c6d8;
|
|
430
|
-
for (let i = 0; i < data.length; i++) {
|
|
431
|
-
h1 = ((h1 << 5) - h1 + data[i]) | 0;
|
|
432
|
-
h2 = ((h2 << 5) - h2 + (h1 ^ data[i])) | 0;
|
|
433
|
-
}
|
|
434
|
-
for (let i = 0; i < 16; i++) {
|
|
435
|
-
result[i] = (h1 >> (i * 2)) & 0xFF;
|
|
436
|
-
result[i + 16] = (h2 >> (i * 2)) & 0xFF;
|
|
437
|
-
}
|
|
438
|
-
return result;
|
|
439
|
-
}
|
|
440
|
-
// Synchronous AES encryption (simplified)
|
|
441
|
-
aesEncryptSync(data, key) {
|
|
442
|
-
// This is a simplified implementation for compatibility
|
|
443
|
-
// It's not as secure as the Web Crypto API
|
|
444
|
-
const result = new Uint8Array(data.length);
|
|
445
|
-
// XOR-based cipher (not actual AES, just for compatibility)
|
|
446
|
-
for (let i = 0; i < data.length; i++) {
|
|
447
|
-
result[i] = data[i] ^ key[i % key.length];
|
|
448
|
-
}
|
|
449
|
-
return result;
|
|
450
|
-
}
|
|
451
|
-
// Synchronous AES decryption (simplified)
|
|
452
|
-
aesDecryptSync(data, key) {
|
|
453
|
-
// For a simple XOR cipher, encryption and decryption are the same operation
|
|
454
|
-
return this.aesEncryptSync(data, key);
|
|
455
|
-
}
|
|
456
|
-
arrayBufferToBase64(buffer) {
|
|
457
|
-
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
458
|
-
let binary = '';
|
|
459
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
460
|
-
binary += String.fromCharCode(bytes[i]);
|
|
461
|
-
}
|
|
462
|
-
return btoa(binary);
|
|
463
|
-
}
|
|
464
|
-
base64ToArrayBuffer(base64) {
|
|
465
|
-
const binaryString = atob(base64);
|
|
466
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
467
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
468
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
469
|
-
}
|
|
470
|
-
return bytes.buffer;
|
|
471
|
-
}
|
|
472
|
-
// Async versions of the methods for future use
|
|
473
|
-
async encryptAsync(str, key = this.appID) {
|
|
474
|
-
if (!str || key === '')
|
|
475
|
-
return '';
|
|
476
|
-
try {
|
|
477
|
-
const encoder = new TextEncoder();
|
|
478
|
-
const data = encoder.encode(JSON.stringify(str));
|
|
479
|
-
const keyMaterial = await this.getKeyMaterial(key);
|
|
480
|
-
const derivedKey = await this.deriveKey(keyMaterial, encoder.encode(key));
|
|
481
|
-
const iv = encoder.encode(key.padEnd(16, key).substring(0, 16));
|
|
482
|
-
const encryptedBuffer = await window.crypto.subtle.encrypt({
|
|
483
|
-
name: 'AES-CBC',
|
|
484
|
-
iv
|
|
485
|
-
}, derivedKey, data);
|
|
486
|
-
return this.arrayBufferToBase64(encryptedBuffer);
|
|
487
|
-
}
|
|
488
|
-
catch (error) {
|
|
489
|
-
console.log(error);
|
|
490
|
-
return '';
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
async decryptAsync(str, key = this.appID) {
|
|
494
|
-
if (!str || key === '')
|
|
495
|
-
return undefined;
|
|
496
|
-
try {
|
|
497
|
-
const encryptedData = this.base64ToArrayBuffer(str);
|
|
498
|
-
const keyMaterial = await this.getKeyMaterial(key);
|
|
499
|
-
const derivedKey = await this.deriveKey(keyMaterial, new TextEncoder().encode(key));
|
|
500
|
-
const iv = new TextEncoder().encode(key.padEnd(16, key).substring(0, 16));
|
|
501
|
-
const decryptedBuffer = await window.crypto.subtle.decrypt({
|
|
502
|
-
name: 'AES-CBC',
|
|
503
|
-
iv
|
|
504
|
-
}, derivedKey, encryptedData);
|
|
505
|
-
return new TextDecoder().decode(decryptedBuffer);
|
|
506
|
-
}
|
|
507
|
-
catch (error) {
|
|
508
|
-
console.log(error);
|
|
509
|
-
return undefined;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
async getKeyMaterial(key) {
|
|
513
|
-
const encoder = new TextEncoder();
|
|
514
|
-
return window.crypto.subtle.importKey('raw', encoder.encode(key), { name: 'PBKDF2' }, false, ['deriveBits', 'deriveKey']);
|
|
515
|
-
}
|
|
516
|
-
async deriveKey(keyMaterial, salt) {
|
|
517
|
-
return window.crypto.subtle.deriveKey({
|
|
518
|
-
name: 'PBKDF2',
|
|
519
|
-
salt,
|
|
520
|
-
iterations: 100000,
|
|
521
|
-
hash: 'SHA-256'
|
|
522
|
-
}, keyMaterial, { name: 'AES-CBC', length: 256 }, false, ['encrypt', 'decrypt']);
|
|
384
|
+
const hash = CryptoJS.SHA256(normalizedURL);
|
|
385
|
+
const signature = hash.toString(CryptoJS.enc.Hex);
|
|
386
|
+
return signature;
|
|
523
387
|
}
|
|
524
388
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SymmetricalEncryptionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
525
389
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SymmetricalEncryptionService, providedIn: 'root' }); }
|
|
@@ -579,11 +443,11 @@ class ObjectMergerService {
|
|
|
579
443
|
const value = options[key];
|
|
580
444
|
if (value !== null &&
|
|
581
445
|
value !== undefined &&
|
|
582
|
-
!(typeof value === 'number')
|
|
583
|
-
!(typeof value === 'boolean')
|
|
446
|
+
!(typeof value === 'number') ||
|
|
447
|
+
!(typeof value === 'boolean') ||
|
|
584
448
|
!(this.isNonEmptyString(value)) &&
|
|
585
|
-
|
|
586
|
-
|
|
449
|
+
!(Array.isArray(value) && value.length === 0) &&
|
|
450
|
+
!(typeof value === 'object' && !Array.isArray(value))) {
|
|
587
451
|
merged[key] = value;
|
|
588
452
|
}
|
|
589
453
|
}
|