@adaskothebeast/angular-date-http-interceptor 2.0.0 → 3.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Adam Pluciński
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -337,33 +337,18 @@ This will initiate the fetch when your component mounts and dispatch either a su
337
337
 
338
338
  Please adjust the code according to your requirements and project structure.
339
339
 
340
- ### Axios
340
+ ### Axios with AxiosInstanceManager
341
341
 
342
- To use the `hierarchicalConvertToDate` function when making requests with Axios, you can make use of Axios' response interceptors. These are functions that Axios will call after receiving a response, but before returning the response to your code.
342
+ The AxiosInstanceManager class simplifies the process of using Axios with the `hierarchicalConvertToDate` function. By utilizing this class, you can easily create and use a centralized Axios instance with a response interceptor that automatically processes response data.
343
343
 
344
- Here is how you might create such an interceptor:
344
+ Here's how to use AxiosInstanceManager:
345
345
 
346
346
  ```ts
347
- import axios from 'axios';
348
-
349
- // Adjust this import as needed - this will import adjustment function for pure js Date object
347
+ import { AxiosInstanceManager } from '@adaskothebeast/axios-interceptor';
350
348
  import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
351
349
 
352
- // Create an instance of axios
353
- const instance = axios.create();
354
-
355
- // Add a response interceptor
356
- instance.interceptors.response.use((response) => {
357
- // Any status code that lies within the range of 2xx cause this function to trigger
358
- // Parse the dates in the response data
359
- hierarchicalConvertToDate(response.data);
360
- // Then return the response object
361
- return response;
362
- }, (error) => {
363
- // Any status codes that falls outside the range of 2xx cause this function to trigger
364
- // You can handle the error here
365
- return Promise.reject(error);
366
- });
350
+ // Create an Axios instance using AxiosInstanceManager
351
+ const instance = AxiosInstanceManager.createInstance(hierarchicalConvertToDate);
367
352
 
368
353
  async function fetchApiData() {
369
354
  try {
@@ -377,8 +362,9 @@ async function fetchApiData() {
377
362
  fetchApiData();
378
363
  ```
379
364
 
380
- In the code above, `instance.interceptors.response.use` is used to add a response interceptor to the Axios instance. This interceptor calls `hierarchicalConvertToDate` on `response.data` to convert any date strings into Date objects. The modified response is then returned.
365
+ In the code above:
381
366
 
382
- The function `fetchApiData` uses the Axios instance to make a GET request, then logs the response data, which will have had date strings parsed into Date objects by the interceptor. If there's an error with the request, it's caught and logged.
367
+ - The createInstance method of AxiosInstanceManager is used to create and configure an Axios instance. This instance is configured with a response interceptor that applies hierarchicalConvertToDate to response.data. This conversion function processes any date strings in the response data into JavaScript Date objects (or in case of other libs proper class for given date lib).
368
+ - The fetchApiData function demonstrates using the configured Axios instance to make a GET request. The response data, with date strings already converted into Date (or in case of other libs proper class for given date lib) objects, is logged to the console. Errors from the request are caught and logged.
383
369
 
384
- Remember to adjust the code according to your project structure and requirements.
370
+ This approach encapsulates the Axios configuration, making your code cleaner and more maintainable. Remember to adjust imports and function calls as per your project's file structure and requirements.
@@ -4,9 +4,9 @@ import { NgModule } from '@angular/core';
4
4
  import { HierarchicalDateHttpInterceptor } from './hierarchical-date-http-interceptor';
5
5
  import * as i0 from "@angular/core";
6
6
  export class AngularDateHttpInterceptorModule {
7
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
8
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, imports: [CommonModule] }); }
9
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, providers: [
7
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
8
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, imports: [CommonModule] }); }
9
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, providers: [
10
10
  {
11
11
  provide: HTTP_INTERCEPTORS,
12
12
  useClass: HierarchicalDateHttpInterceptor,
@@ -14,7 +14,7 @@ export class AngularDateHttpInterceptorModule {
14
14
  },
15
15
  ], imports: [CommonModule] }); }
16
16
  }
17
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, decorators: [{
17
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, decorators: [{
18
18
  type: NgModule,
19
19
  args: [{
20
20
  imports: [CommonModule],
@@ -41,10 +41,10 @@ export class HierarchicalDateHttpInterceptor {
41
41
  return event;
42
42
  }));
43
43
  }
44
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: HierarchicalDateHttpInterceptor, deps: [{ token: HIERARCHICAL_DATE_ADJUST_FUNCTION }], target: i0.ɵɵFactoryTarget.Injectable }); }
45
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: HierarchicalDateHttpInterceptor }); }
44
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: HierarchicalDateHttpInterceptor, deps: [{ token: HIERARCHICAL_DATE_ADJUST_FUNCTION }], target: i0.ɵɵFactoryTarget.Injectable }); }
45
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: HierarchicalDateHttpInterceptor }); }
46
46
  }
47
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: HierarchicalDateHttpInterceptor, decorators: [{
47
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: HierarchicalDateHttpInterceptor, decorators: [{
48
48
  type: Injectable
49
49
  }], ctorParameters: () => [{ type: undefined, decorators: [{
50
50
  type: Inject,
@@ -44,10 +44,10 @@ class HierarchicalDateHttpInterceptor {
44
44
  return event;
45
45
  }));
46
46
  }
47
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: HierarchicalDateHttpInterceptor, deps: [{ token: HIERARCHICAL_DATE_ADJUST_FUNCTION }], target: i0.ɵɵFactoryTarget.Injectable }); }
48
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: HierarchicalDateHttpInterceptor }); }
47
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: HierarchicalDateHttpInterceptor, deps: [{ token: HIERARCHICAL_DATE_ADJUST_FUNCTION }], target: i0.ɵɵFactoryTarget.Injectable }); }
48
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: HierarchicalDateHttpInterceptor }); }
49
49
  }
50
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: HierarchicalDateHttpInterceptor, decorators: [{
50
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: HierarchicalDateHttpInterceptor, decorators: [{
51
51
  type: Injectable
52
52
  }], ctorParameters: () => [{ type: undefined, decorators: [{
53
53
  type: Inject,
@@ -55,9 +55,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.2", ngImpor
55
55
  }] }] });
56
56
 
57
57
  class AngularDateHttpInterceptorModule {
58
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
59
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, imports: [CommonModule] }); }
60
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, providers: [
58
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
59
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, imports: [CommonModule] }); }
60
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, providers: [
61
61
  {
62
62
  provide: HTTP_INTERCEPTORS,
63
63
  useClass: HierarchicalDateHttpInterceptor,
@@ -65,7 +65,7 @@ class AngularDateHttpInterceptorModule {
65
65
  },
66
66
  ], imports: [CommonModule] }); }
67
67
  }
68
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.2", ngImport: i0, type: AngularDateHttpInterceptorModule, decorators: [{
68
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AngularDateHttpInterceptorModule, decorators: [{
69
69
  type: NgModule,
70
70
  args: [{
71
71
  imports: [CommonModule],
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@adaskothebeast/angular-date-http-interceptor",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
+ "license": "MIT",
5
+ "author": "Adam Pluciński <adaskothebeast@gmail.com> (https://github.com/adaskothebeast)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/AdaskoTheBeAsT/date-interceptors.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/AdaskoTheBeAsT/date-interceptors/issues"
12
+ },
13
+ "homepage": "https://github.com/AdaskoTheBeAsT/date-interceptors",
4
14
  "peerDependencies": {
5
- "@angular/common": "^17.0.2",
6
- "@angular/core": "^17.0.2",
15
+ "@angular/common": "^17.0.8",
16
+ "@angular/core": "^17.0.8",
7
17
  "rxjs": "^7.8.1"
8
18
  },
9
19
  "sideEffects": false,