angular-toolbox 0.11.1 → 0.11.3

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.
Files changed (22) hide show
  1. package/README.md +1 -1
  2. package/esm2022/lib/framework/mock/http/util/fetch-client-response-type.enum.mjs +5 -1
  3. package/esm2022/lib/framework/mock/http/util/fetch-client.builder.mjs +3 -2
  4. package/esm2022/lib/model/business/mock/http/config/http-mock-production-policy.enum.mjs +27 -0
  5. package/esm2022/lib/model/business/mock/http/config/http-mocking-framework-config.mjs +9 -0
  6. package/esm2022/lib/model/business/mock/http/config/http-mocking-framework-config.provider.mjs +33 -0
  7. package/esm2022/lib/model/business/mock/http/config/index.mjs +4 -0
  8. package/esm2022/lib/model/business/mock/http/index.mjs +2 -1
  9. package/esm2022/lib/model/service/mock/http/http-mock.service.mjs +45 -6
  10. package/esm2022/lib/model/service/version/angular-toolbox-version.service.mjs +3 -3
  11. package/esm2022/lib/util/http-mocking-framework-config.manager.mjs +129 -0
  12. package/fesm2022/angular-toolbox.mjs +243 -9
  13. package/fesm2022/angular-toolbox.mjs.map +1 -1
  14. package/lib/framework/mock/http/util/fetch-client-response-type.enum.d.ts +5 -1
  15. package/lib/model/business/mock/http/config/http-mock-production-policy.enum.d.ts +24 -0
  16. package/lib/model/business/mock/http/config/http-mocking-framework-config.d.ts +21 -0
  17. package/lib/model/business/mock/http/config/http-mocking-framework-config.provider.d.ts +21 -0
  18. package/lib/model/business/mock/http/config/index.d.ts +3 -0
  19. package/lib/model/business/mock/http/index.d.ts +1 -0
  20. package/lib/model/service/mock/http/http-mock.service.d.ts +35 -2
  21. package/lib/util/http-mocking-framework-config.manager.d.ts +66 -0
  22. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, NgModule, EventEmitter, Component, Directive, Output, Input, HostListener, Inject, inject, Pipe } from '@angular/core';
2
+ import { Injectable, NgModule, EventEmitter, Component, Directive, Output, Input, HostListener, Inject, isDevMode, Optional, inject, Pipe } from '@angular/core';
3
3
  import * as i1 from '@angular/router';
4
4
  import { RouterModule } from '@angular/router';
5
5
  import { DOCUMENT, XhrFactory } from '@angular/common';
@@ -543,8 +543,8 @@ class AbstractVersionManager {
543
543
  const LAYERS_VERSION_CONFIG = {
544
544
  major: 0,
545
545
  minor: 11,
546
- patch: 1,
547
- buildTimestamp: 1722003985958,
546
+ patch: 3,
547
+ buildTimestamp: 1722599248501,
548
548
  metadata: "beta"
549
549
  };
550
550
  /**
@@ -1353,6 +1353,73 @@ const DARK_MODE_CONFIG = {
1353
1353
  * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
1354
1354
  */
1355
1355
 
1356
+ /**
1357
+ * @license
1358
+ * Copyright Pascal ECHEMANN. All Rights Reserved.
1359
+ *
1360
+ * Use of this source code is governed by an MIT-style license that can be found in
1361
+ * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
1362
+ */
1363
+
1364
+ /**
1365
+ * @license
1366
+ * Copyright Pascal ECHEMANN. All Rights Reserved.
1367
+ *
1368
+ * Use of this source code is governed by an MIT-style license that can be found in
1369
+ * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
1370
+ */
1371
+ /**
1372
+ * The list of constant values that can be passed to the `productionPolicy` of the `HttpMockingFrameworkConfig` interface.
1373
+ */
1374
+ var HttpMockProductionPolicy;
1375
+ (function (HttpMockProductionPolicy) {
1376
+ /**
1377
+ * Indicates that the framework intercepts requests silently in producion mode.
1378
+ */
1379
+ HttpMockProductionPolicy[HttpMockProductionPolicy["SILENT"] = 0] = "SILENT";
1380
+ /**
1381
+ * Indicates that the framework has to send a warning message to the console when a request is intercetped in producion mode.
1382
+ */
1383
+ HttpMockProductionPolicy[HttpMockProductionPolicy["WARNING"] = 1] = "WARNING";
1384
+ /**
1385
+ * Indicates that the framework trhows an error when a request is intercetped in producion mode.
1386
+ */
1387
+ HttpMockProductionPolicy[HttpMockProductionPolicy["ERROR"] = 2] = "ERROR";
1388
+ })(HttpMockProductionPolicy || (HttpMockProductionPolicy = {}));
1389
+ ;
1390
+
1391
+ /**
1392
+ * @license
1393
+ * Copyright Pascal ECHEMANN. All Rights Reserved.
1394
+ *
1395
+ * Use of this source code is governed by an MIT-style license that can be found in
1396
+ * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
1397
+ */
1398
+ /**
1399
+ * The default provider for the HTTP Mocking Framework configuration. You typically define
1400
+ * the custom properties in the main NgModule declaration to initialize the HTTP Mocking Framework:
1401
+ *
1402
+ * @NgModule({
1403
+ * ...
1404
+ * providers: [
1405
+ * { provide: HTTP_MOCKING_FRAMEWORK_CONFIG, useValue: { disableVisualFlag: true, productionPolicy: HttpMockProductionPolicy.WARNING } }
1406
+ * ],
1407
+ * ...
1408
+ * });
1409
+ */
1410
+ const HTTP_MOCKING_FRAMEWORK_CONFIG = {
1411
+ /**
1412
+ * Indicates whether the visual flag is visible (`false`), or not (`true`).
1413
+ * Default value is `false`.
1414
+ */
1415
+ disableVisualFlag: false,
1416
+ /**
1417
+ * Indicates the behavior of the framework when it is used in production mode.
1418
+ * Default value is `HttpMockProductionPolicy.ERROR`.
1419
+ */
1420
+ productionPolicy: HttpMockProductionPolicy.ERROR
1421
+ };
1422
+
1356
1423
  /**
1357
1424
  * @license
1358
1425
  * Copyright Pascal ECHEMANN. All Rights Reserved.
@@ -2615,6 +2682,133 @@ const stringToTokenData = (str, options = {}) => {
2615
2682
  return new TokenData(tokens, delimiter);
2616
2683
  };
2617
2684
 
2685
+ /**
2686
+ * @license
2687
+ * Copyright Pascal ECHEMANN. All Rights Reserved.
2688
+ *
2689
+ * Use of this source code is governed by an MIT-style license that can be found in
2690
+ * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
2691
+ */
2692
+ /**
2693
+ * @private
2694
+ */
2695
+ const POLICY_WARNING = "HTTP Mocking Framework is running in production mode";
2696
+ /**
2697
+ * @private
2698
+ */
2699
+ const POLICY_ERROR = new HttpMockServiceError(POLICY_WARNING + ": remove all framework references or change the 'productionPolicy' property value of the HTTP_MOCKING_FRAMEWORK_CONFIG provider.");
2700
+ /**
2701
+ * @private
2702
+ */
2703
+ const FLAG_ID = "http-mocking-framework-flag";
2704
+ /**
2705
+ * The object that manages the HTTP Mocking Framework options.
2706
+ */
2707
+ class HttpMockingFrameworkConfigManager {
2708
+ /**
2709
+ * Returns the value specified by the `disableVisualFlag` of the `HttpMockingFrameworkConfig` provider,
2710
+ * or `false` when no provider is defined.
2711
+ */
2712
+ get disableVisualFlag() {
2713
+ const cfg = this._config;
2714
+ return cfg && cfg.disableVisualFlag ? cfg.disableVisualFlag : false;
2715
+ }
2716
+ /**
2717
+ * Returns the value specified by the `productionPolicy` of the `HttpMockingFrameworkConfig` provider,
2718
+ * or `HttpMockProductionPolicy.ERROR` when no provider is defined.
2719
+ */
2720
+ get productionPolicy() {
2721
+ return this._prodPolicy;
2722
+ }
2723
+ /**
2724
+ * @private
2725
+ * Creates and Initializes the manager with the specified config.
2726
+ *
2727
+ * @param document The reference to the `Document` object, injected by Angular.
2728
+ * @param isDevMode Indicates wheter Angular runs in development mode (`true`), or in production mode (`false`).
2729
+ * @param config The `HttpMockingFrameworkConfi` provider.
2730
+ */
2731
+ constructor(document, isDevMode, config) {
2732
+ this._isProdMode = !isDevMode;
2733
+ this._document = document;
2734
+ this._config = config;
2735
+ this._prodPolicy = config && config.productionPolicy !== undefined ? config.productionPolicy : HttpMockProductionPolicy.ERROR;
2736
+ this.checkPolicy();
2737
+ this.createVisualFlag(document, config);
2738
+ }
2739
+ /**
2740
+ * Apply a strategy depending on the current production policy and environment.
2741
+ * @param route An optional parameter used when the methhod is associated to a HTTP request.
2742
+ * Must be the representation of the intercepted route path.
2743
+ * @param method An optional parameter used when the methhod is associated to a HTTP request.
2744
+ * Must be the representation of the intercepted HTTP method.
2745
+ */
2746
+ checkPolicy(route, method = undefined) {
2747
+ if (!this._isProdMode)
2748
+ return;
2749
+ if (this._prodPolicy === HttpMockProductionPolicy.ERROR)
2750
+ throw POLICY_ERROR;
2751
+ if (this._prodPolicy === HttpMockProductionPolicy.SILENT)
2752
+ return;
2753
+ const routeMsg = route ? `: intercepted request=[path=${route}, method=${method?.toUpperCase()}]` : ".";
2754
+ console.warn(POLICY_WARNING + routeMsg);
2755
+ }
2756
+ /**
2757
+ * @private
2758
+ */
2759
+ destroy() {
2760
+ const cfg = this._config;
2761
+ const noFlag = (cfg && cfg.disableVisualFlag) === true;
2762
+ this._config = null;
2763
+ if (noFlag)
2764
+ return;
2765
+ const doc = this._document;
2766
+ const flag = doc.getElementById(FLAG_ID);
2767
+ if (flag) {
2768
+ flag.onmouseover = flag.onmouseout = null;
2769
+ doc.body.removeChild(flag);
2770
+ }
2771
+ }
2772
+ /**
2773
+ * @private
2774
+ */
2775
+ createVisualFlag(document, config) {
2776
+ if (config && config.disableVisualFlag)
2777
+ return;
2778
+ const flag = document.createElement("div");
2779
+ const text = document.createTextNode("HTTP Mocking Framwork");
2780
+ const style = flag.style;
2781
+ const body = document.body;
2782
+ flag.setAttribute("id", FLAG_ID);
2783
+ style.backgroundColor = "red";
2784
+ style.color = "white";
2785
+ style.textAlign = "center";
2786
+ style.position = "fixed";
2787
+ style.width = "100%";
2788
+ style.overflow = "hidden";
2789
+ style.height = "26px";
2790
+ style.transition = "all 0.25s ease-in-out";
2791
+ style.zIndex = "10000";
2792
+ style.opacity = "1";
2793
+ style.userSelect = "none";
2794
+ flag.onmouseover = () => {
2795
+ style.height = "26px";
2796
+ style.opacity = "1";
2797
+ };
2798
+ flag.onmouseout = () => {
2799
+ style.height = "6px";
2800
+ style.opacity = "0.35";
2801
+ };
2802
+ flag.appendChild(text);
2803
+ body.insertBefore(flag, body.firstChild);
2804
+ setTimeout(() => {
2805
+ style.height = "4px";
2806
+ style.opacity = "0.35";
2807
+ }, 4000);
2808
+ }
2809
+ }
2810
+ ;
2811
+
2618
2812
  /**
2619
2813
  * @license
2620
2814
  * Copyright Pascal ECHEMANN. All Rights Reserved.
@@ -2630,8 +2824,23 @@ const HTTP_MOCK_SERVICE = "HttpMockService";
2630
2824
  /**
2631
2825
  * The `HttpMockService` class provides the API for managing HTTP mock configuration objects.
2632
2826
  */
2633
- class HttpMockService {
2634
- constructor() {
2827
+ class HttpMockService extends IdentifiableComponent {
2828
+ /**
2829
+ * Returns the vreference to the `HttpMockingFrameworkConfigManager` instance,
2830
+ * associated with this service.
2831
+ */
2832
+ get configMmanager() {
2833
+ return this._configMmanager;
2834
+ }
2835
+ /**
2836
+ * @private
2837
+ * Creates a new `HttpMockService` instance.
2838
+ *
2839
+ * @param _document The reference to the app document.
2840
+ * @param config The optional config provider for the HTTP Mocking Framework.
2841
+ */
2842
+ constructor(document, config) {
2843
+ super(HTTP_MOCK_SERVICE);
2635
2844
  /**
2636
2845
  * @private
2637
2846
  * Ensures that class type is still accessible after TypeScript compilation.
@@ -2652,6 +2861,14 @@ class HttpMockService {
2652
2861
  * The reference to the current app URL origin.
2653
2862
  */
2654
2863
  this.APP_ORIGIN = window.location.origin;
2864
+ this._configMmanager = new HttpMockingFrameworkConfigManager(document, isDevMode(), config);
2865
+ }
2866
+ /**
2867
+ * @private
2868
+ */
2869
+ ngOnDestroy() {
2870
+ this._configMmanager.checkPolicy();
2871
+ this._configMmanager.destroy();
2655
2872
  }
2656
2873
  /**
2657
2874
  * Adds the specified `HttpMockConfig` object to this `HttpMockService` instance.
@@ -2661,6 +2878,7 @@ class HttpMockService {
2661
2878
  */
2662
2879
  addConfig(config) {
2663
2880
  const origin = config.origin || this.APP_ORIGIN;
2881
+ this._configMmanager.checkPolicy();
2664
2882
  this.checkOrigin(origin);
2665
2883
  let id = config.id;
2666
2884
  if (!id) {
@@ -2690,6 +2908,7 @@ class HttpMockService {
2690
2908
  * @param uuid The UUID of the configuration to remove.
2691
2909
  */
2692
2910
  removeConfig(uuid) {
2911
+ this._configMmanager.checkPolicy();
2693
2912
  if (!this.hasRegisteredConfig(uuid))
2694
2913
  return;
2695
2914
  const configId = uuid.toString();
@@ -2704,6 +2923,7 @@ class HttpMockService {
2704
2923
  * Removes all registred configurations from this `HttpMockService` instance.
2705
2924
  */
2706
2925
  clearConfigs() {
2926
+ this._configMmanager.checkPolicy();
2707
2927
  this._configList.clear();
2708
2928
  this._configIdList.length = 0;
2709
2929
  }
@@ -2728,6 +2948,7 @@ class HttpMockService {
2728
2948
  getRouteConfig(url, method) {
2729
2949
  const urlConfigList = this._configList.get(url.origin);
2730
2950
  const route = url.pathname;
2951
+ this._configMmanager.checkPolicy(route, method);
2731
2952
  let result = undefined;
2732
2953
  if (!urlConfigList)
2733
2954
  return result;
@@ -2837,7 +3058,7 @@ class HttpMockService {
2837
3058
  cleanConfig(storage, configId) {
2838
3059
  return storage.filter((value) => value.configId !== configId);
2839
3060
  }
2840
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.3", ngImport: i0, type: HttpMockService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
3061
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.3", ngImport: i0, type: HttpMockService, deps: [{ token: DOCUMENT }, { token: HTTP_MOCKING_FRAMEWORK_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
2841
3062
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.3", ngImport: i0, type: HttpMockService, providedIn: 'root' }); }
2842
3063
  }
2843
3064
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.3", ngImport: i0, type: HttpMockService, decorators: [{
@@ -2845,7 +3066,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.3", ngImpor
2845
3066
  args: [{
2846
3067
  providedIn: 'root'
2847
3068
  }]
2848
- }] });
3069
+ }], ctorParameters: () => [{ type: Document, decorators: [{
3070
+ type: Inject,
3071
+ args: [DOCUMENT]
3072
+ }] }, { type: undefined, decorators: [{
3073
+ type: Optional
3074
+ }, {
3075
+ type: Inject,
3076
+ args: [HTTP_MOCKING_FRAMEWORK_CONFIG]
3077
+ }] }] });
2849
3078
 
2850
3079
  /**
2851
3080
  * @license
@@ -3180,6 +3409,10 @@ var FetchClientResponseType;
3180
3409
  * The response is always decoded using UTF-8.
3181
3410
  */
3182
3411
  FetchClientResponseType["TEXT"] = "text";
3412
+ /**
3413
+ * Allows to return the response as a promise that resolves with a `Response` object.
3414
+ */
3415
+ FetchClientResponseType["RESPONSE"] = "response";
3183
3416
  })(FetchClientResponseType || (FetchClientResponseType = {}));
3184
3417
 
3185
3418
  /**
@@ -3204,8 +3437,9 @@ class FetchClientBuilder {
3204
3437
  */
3205
3438
  static buildFetchClient(input, init = null, responseType = FetchClientResponseType.JSON) {
3206
3439
  return from(fetch(input, init || undefined).then((response) => {
3440
+ const rspType = responseType;
3207
3441
  if (response.ok)
3208
- return FetchClientBuilder.buildResponseStrategy(response, responseType);
3442
+ return rspType !== FetchClientResponseType.RESPONSE ? FetchClientBuilder.buildResponseStrategy(response, rspType) : response;
3209
3443
  throw new HttpErrorResponse({
3210
3444
  status: response.status,
3211
3445
  statusText: response.statusText
@@ -4203,5 +4437,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.3", ngImpor
4203
4437
  * Generated bundle index. Do not edit.
4204
4438
  */
4205
4439
 
4206
- export { APP_PRIDGE_REF, AbstractSubscriptionManager, AbstractVersionManager, AnchorLinklDirective, AngularToolboxLogoComponent, AngularToolboxModule, AngularToolboxVersionService, AppBridgeError, AppBrigeService, ArrayList, ArrayListEvent, ArrayListEventType, BIGINT, BOOLEAN, BUTTON_ROLE, ButtonRoleDirective, CSS_PROP, ContentRendererDirective, DARK_MODE_CONFIG, DarkModeService, EMPTY_STRING, FUNCTION, FetchClientBuilder, FetchClientResponseType, HTTP_MOCK_SERVICE, HttpHeadersMockBuilder, HttpMock, HttpMockService, HttpMockServiceError, HttpResponseMockBuilder, IdentifiableComponent, IntegrityError, LINK_ROLE, NUMBER, NavigateToUrlDirective, OBJECT, STORAGE_KEY, STRING, SYMBOL, SafeHtmlPipe, ScrollService, SubscriptionError, SubscriptionService, UNDEFINED, Uuid, VERSION_CONFIG, VersionService, httpHeadersMock, httpMockFactory, httpResponseMock };
4440
+ export { APP_PRIDGE_REF, AbstractSubscriptionManager, AbstractVersionManager, AnchorLinklDirective, AngularToolboxLogoComponent, AngularToolboxModule, AngularToolboxVersionService, AppBridgeError, AppBrigeService, ArrayList, ArrayListEvent, ArrayListEventType, BIGINT, BOOLEAN, BUTTON_ROLE, ButtonRoleDirective, CSS_PROP, ContentRendererDirective, DARK_MODE_CONFIG, DarkModeService, EMPTY_STRING, FUNCTION, FetchClientBuilder, FetchClientResponseType, HTTP_MOCKING_FRAMEWORK_CONFIG, HTTP_MOCK_SERVICE, HttpHeadersMockBuilder, HttpMock, HttpMockProductionPolicy, HttpMockService, HttpMockServiceError, HttpResponseMockBuilder, IdentifiableComponent, IntegrityError, LINK_ROLE, NUMBER, NavigateToUrlDirective, OBJECT, STORAGE_KEY, STRING, SYMBOL, SafeHtmlPipe, ScrollService, SubscriptionError, SubscriptionService, UNDEFINED, Uuid, VERSION_CONFIG, VersionService, httpHeadersMock, httpMockFactory, httpResponseMock };
4207
4441
  //# sourceMappingURL=angular-toolbox.mjs.map