nestjs-http-promise
Advanced tools
Comparing version
@@ -73,5 +73,3 @@ "use strict"; | ||
} | ||
const providers = [ | ||
this.createAsyncOptionsProvider(options) | ||
]; | ||
const providers = [this.createAsyncOptionsProvider(options)]; | ||
if (options.useClass) | ||
@@ -104,3 +102,4 @@ providers.push({ | ||
}; | ||
HttpModule = HttpModule_1 = __decorate([ | ||
exports.HttpModule = HttpModule; | ||
exports.HttpModule = HttpModule = HttpModule_1 = __decorate([ | ||
(0, common_1.Module)({ | ||
@@ -117,2 +116,1 @@ providers: [ | ||
], HttpModule); | ||
exports.HttpModule = HttpModule; |
@@ -20,3 +20,2 @@ "use strict"; | ||
const common_1 = require("@nestjs/common"); | ||
const common_2 = require("@nestjs/common"); | ||
const axios_1 = __importDefault(require("axios")); | ||
@@ -40,7 +39,7 @@ const http_constants_1 = require("./http.constants"); | ||
}; | ||
HttpService = __decorate([ | ||
exports.HttpService = HttpService; | ||
exports.HttpService = HttpService = __decorate([ | ||
(0, common_1.Injectable)(), | ||
__param(0, (0, common_2.Inject)(http_constants_1.AXIOS_INSTANCE_TOKEN)), | ||
__param(0, (0, common_1.Inject)(http_constants_1.AXIOS_INSTANCE_TOKEN)), | ||
__metadata("design:paramtypes", [Function]) | ||
], HttpService); | ||
exports.HttpService = HttpService; |
import { ModuleMetadata, Provider, Type } from '@nestjs/common'; | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { IAxiosRetryConfig } from 'axios-retry'; | ||
export declare type HttpModuleOptions = (AxiosRequestConfig & IAxiosRetryConfig); | ||
export type HttpModuleOptions = AxiosRequestConfig & IAxiosRetryConfig; | ||
export interface HttpModuleOptionsFactory { | ||
@@ -6,0 +6,0 @@ createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions; |
export const AXIOS_INSTANCE_TOKEN = 'AXIOS_INSTANCE_TOKEN'; | ||
export const HTTP_MODULE_ID = 'HTTP_MODULE_ID'; | ||
export const HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS'; | ||
export const HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS'; |
@@ -21,3 +21,3 @@ import { DynamicModule, Module, Provider } from '@nestjs/common'; | ||
return axiosInstance; | ||
} | ||
}; | ||
@@ -59,3 +59,4 @@ @Module({ | ||
provide: AXIOS_INSTANCE_TOKEN, | ||
useFactory: (config: HttpModuleOptions) => createAxiosInstance(config), | ||
useFactory: (config: HttpModuleOptions) => | ||
createAxiosInstance(config), | ||
inject: [HTTP_MODULE_OPTIONS], | ||
@@ -73,3 +74,3 @@ }, | ||
private static createAsyncProviders( | ||
options: HttpModuleAsyncOptions, | ||
options: HttpModuleAsyncOptions, | ||
): Provider[] { | ||
@@ -80,11 +81,9 @@ if (options.useExisting || options.useFactory) { | ||
const providers = [ | ||
this.createAsyncOptionsProvider(options) | ||
]; | ||
const providers = [this.createAsyncOptionsProvider(options)]; | ||
if(options.useClass) | ||
if (options.useClass) | ||
providers.push({ | ||
provide: options.useClass, | ||
useClass: options.useClass, | ||
}) | ||
}); | ||
@@ -95,3 +94,3 @@ return providers; | ||
private static createAsyncOptionsProvider( | ||
options: HttpModuleAsyncOptions, | ||
options: HttpModuleAsyncOptions, | ||
): Provider { | ||
@@ -107,6 +106,4 @@ if (options.useFactory) { | ||
let inject; | ||
if (options.useExisting) | ||
inject = [options.useExisting]; | ||
else if (options.useClass) | ||
inject = [options.useClass]; | ||
if (options.useExisting) inject = [options.useExisting]; | ||
else if (options.useClass) inject = [options.useClass]; | ||
@@ -116,6 +113,6 @@ return { | ||
useFactory: async (optionsFactory: HttpModuleOptionsFactory) => | ||
optionsFactory.createHttpOptions(), | ||
optionsFactory.createHttpOptions(), | ||
inject, | ||
}; | ||
} | ||
} | ||
} |
@@ -1,33 +0,32 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Inject } from '@nestjs/common'; | ||
import Axios ,{ AxiosInstance } from 'axios'; | ||
import { AXIOS_INSTANCE_TOKEN } from "./http.constants"; | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
import Axios, { AxiosInstance } from 'axios'; | ||
import { AXIOS_INSTANCE_TOKEN } from './http.constants'; | ||
@Injectable() | ||
export class HttpService { | ||
public readonly put: typeof Axios.put; | ||
public readonly post: typeof Axios.post; | ||
public readonly patch: typeof Axios.patch; | ||
public readonly head: typeof Axios.patch; | ||
public readonly delete: typeof Axios.delete; | ||
public readonly get: typeof Axios.get; | ||
public readonly request: typeof Axios.request; | ||
public readonly put: typeof Axios.put; | ||
public readonly post: typeof Axios.post; | ||
public readonly patch: typeof Axios.patch; | ||
public readonly head: typeof Axios.patch; | ||
public readonly delete: typeof Axios.delete; | ||
public readonly get: typeof Axios.get; | ||
public readonly request: typeof Axios.request; | ||
constructor( | ||
@Inject(AXIOS_INSTANCE_TOKEN) | ||
private readonly instance: AxiosInstance = Axios, | ||
) { | ||
this.put = this.instance.put; | ||
this.post = this.instance.post; | ||
this.patch = this.instance.patch; | ||
this.head = this.instance.head; | ||
this.head = this.instance.head; | ||
this.delete = this.instance.delete; | ||
this.get = this.instance.get; | ||
this.request = this.instance.request; | ||
} | ||
constructor( | ||
@Inject(AXIOS_INSTANCE_TOKEN) | ||
private readonly instance: AxiosInstance = Axios, | ||
) { | ||
this.put = this.instance.put; | ||
this.post = this.instance.post; | ||
this.patch = this.instance.patch; | ||
this.head = this.instance.head; | ||
this.head = this.instance.head; | ||
this.delete = this.instance.delete; | ||
this.get = this.instance.get; | ||
this.request = this.instance.request; | ||
} | ||
get axiosRef(): AxiosInstance { | ||
return this.instance | ||
} | ||
get axiosRef(): AxiosInstance { | ||
return this.instance; | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
export { HttpService } from './http.service' | ||
export { HttpModule } from './http.module' | ||
export * from './interfaces' | ||
export { HttpService } from './http.service'; | ||
export { HttpModule } from './http.module'; | ||
export * from './interfaces'; |
import { ModuleMetadata, Provider, Type } from '@nestjs/common'; | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { IAxiosRetryConfig } from 'axios-retry' | ||
import { IAxiosRetryConfig } from 'axios-retry'; | ||
export type HttpModuleOptions = (AxiosRequestConfig & IAxiosRetryConfig); | ||
export type HttpModuleOptions = AxiosRequestConfig & IAxiosRetryConfig; | ||
export interface HttpModuleOptionsFactory { | ||
createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions; | ||
createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions; | ||
} | ||
export interface HttpModuleAsyncOptions | ||
extends Pick<ModuleMetadata, 'imports'> { | ||
useExisting?: Type<HttpModuleOptionsFactory>; | ||
useClass?: Type<HttpModuleOptionsFactory>; | ||
useFactory?: ( | ||
...args: any[] | ||
) => Promise<HttpModuleOptions> | HttpModuleOptions; | ||
inject?: any[]; | ||
extraProviders?: Provider[]; | ||
} | ||
extends Pick<ModuleMetadata, 'imports'> { | ||
useExisting?: Type<HttpModuleOptionsFactory>; | ||
useClass?: Type<HttpModuleOptionsFactory>; | ||
useFactory?: ( | ||
...args: any[] | ||
) => Promise<HttpModuleOptions> | HttpModuleOptions; | ||
inject?: any[]; | ||
extraProviders?: Provider[]; | ||
} |
{ | ||
"name": "nestjs-http-promise", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"keywords": [ | ||
@@ -20,3 +20,3 @@ "nestjs", | ||
"build": "rimraf -rf dist && tsc -p tsconfig.json", | ||
"format": "prettier --write \"{lib}/**/*.ts\"", | ||
"format": "prettier --write \"lib/**/*.ts\"", | ||
"lint": "eslint 'lib/**/*.ts' --fix", | ||
@@ -30,25 +30,25 @@ "prepare": "npm run build", | ||
"dependencies": { | ||
"axios-retry": "^3.3.1" | ||
"axios-retry": "^4.5.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/common": "^10.0.0", | ||
"@nestjs/core": "^10.0.0", | ||
"@nestjs/platform-express": "^10.0.0", | ||
"@types/node": "^14.18.13", | ||
"@typescript-eslint/eslint-plugin": "^4.33.0", | ||
"@typescript-eslint/parser": "^4.33.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"husky": "^7.0.4", | ||
"lint-staged": "^11.2.6", | ||
"prettier": "^2.6.2", | ||
"reflect-metadata": "^0.1.13", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.6.3" | ||
"@nestjs/common": "^11.0.7", | ||
"@nestjs/core": "^11.0.7", | ||
"@nestjs/platform-express": "^11.0.7", | ||
"@types/node": "^22.13.0", | ||
"@typescript-eslint/eslint-plugin": "^8.22.0", | ||
"@typescript-eslint/parser": "^8.22.0", | ||
"eslint": "^9.19.0", | ||
"eslint-config-prettier": "^10.0.1", | ||
"eslint-plugin-import": "^2.31.0", | ||
"husky": "^9.1.7", | ||
"lint-staged": "^15.4.3", | ||
"prettier": "^3.4.2", | ||
"reflect-metadata": "^0.2.2", | ||
"rimraf": "^6.0.1", | ||
"typescript": "^5.7.3" | ||
}, | ||
"peerDependencies": { | ||
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0", | ||
"reflect-metadata": "^0.1.12", | ||
"axios": "^1.3.0" | ||
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0", | ||
"reflect-metadata": "^0.2.2", | ||
"axios": "^1.4.0" | ||
}, | ||
@@ -55,0 +55,0 @@ "lint-staged": { |
26580
-0.81%27
-3.57%442
-0.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated