Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump axios-retry from 3.8.1 to 3.9.0 #177

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 74 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,76 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: [
'@typescript-eslint/eslint-plugin',
'simple-import-sort',
'no-type-assertion',
'import',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:@typescript-eslint/strict',
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
eqeqeq: 'error',
'no-lonely-if': 'error',
'no-multi-assign': 'error',
'@typescript-eslint/no-shadow': 'error',
'no-useless-return': 'error',
'no-useless-rename': 'error',
'one-var-declaration-per-line': 'error',
'prefer-object-spread': 'error',
'no-unreachable-loop': 'error',
'no-template-curly-in-string': 'error',
'default-case-last': 'error',
'no-array-constructor': 'error',
'no-else-return': 'error',
'no-negated-condition': 'error',
'array-callback-return': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'no-type-assertion/no-type-assertion': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'import/consistent-type-specifier-style': 'error',
'import/no-duplicates': 'error',
'import/no-unresolved': 'error',
curly: 'error',
'no-console': [
'warn',
{
allow: ['warn', 'error'],
},
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
};
quotes: [
'error',
'single',
{
avoidEscape: true,
},
],
'prefer-template': 'error',
'@typescript-eslint/return-await': ['error', 'always'],
},
};
34 changes: 22 additions & 12 deletions lib/http.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { DynamicModule, Module, Provider } from '@nestjs/common';
import type { DynamicModule, Provider } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
import Axios from 'axios';
import axios from 'axios';
import axiosRetry from 'axios-retry';

import { AXIOS_INSTANCE_TOKEN, HTTP_MODULE_ID, HTTP_MODULE_OPTIONS } from './http.constants';
import { HttpService } from './http.service';
import { HttpModuleAsyncOptions, HttpModuleOptions, HttpModuleOptionsFactory } from './interfaces';
import axiosRetry from 'axios-retry';
import type {
HttpModuleAsyncOptions,
HttpModuleOptions,
HttpModuleOptionsFactory,
} from './interfaces';

const createAxiosInstance = (config?: HttpModuleOptions) => {
const axiosInstance = Axios.create(config);
const axiosInstance = axios.create(config);
axiosRetry(axiosInstance, config);
return axiosInstance;
};
Expand Down Expand Up @@ -54,23 +60,24 @@ export class HttpModule {
provide: HTTP_MODULE_ID,
useValue: randomStringGenerator(),
},
...(options.extraProviders || []),
...(options.extraProviders ?? []),
],
};
}

private static createAsyncProviders(options: HttpModuleAsyncOptions): Provider[] {
if (options.useExisting || options.useFactory) {
if (!!options.useExisting || !!options.useFactory) {
return [this.createAsyncOptionsProvider(options)];
}

const providers = [this.createAsyncOptionsProvider(options)];

if (options.useClass)
if (options.useClass) {
providers.push({
provide: options.useClass,
useClass: options.useClass,
});
}

return providers;
}
Expand All @@ -80,18 +87,21 @@ export class HttpModule {
return {
provide: HTTP_MODULE_OPTIONS,
useFactory: options.useFactory,
inject: options.inject || [],
inject: options.inject ?? [],
};
}

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];
}

return {
provide: HTTP_MODULE_OPTIONS,
useFactory: async (optionsFactory: HttpModuleOptionsFactory) =>
optionsFactory.createHttpOptions(),
await optionsFactory.createHttpOptions(),
...(inject && { inject }),
};
}
Expand Down
27 changes: 15 additions & 12 deletions lib/http.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { Injectable } from '@nestjs/common';
import { Inject } from '@nestjs/common';
import Axios, { AxiosInstance } from 'axios';
/* eslint-disable @typescript-eslint/unbound-method */

import { Inject, Injectable } 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,
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 as typeof Axios.patch;
// eslint-disable-next-line no-type-assertion/no-type-assertion
this.head = this.instance.head as typeof axios.patch;
this.delete = this.instance.delete;
this.get = this.instance.get;
this.request = this.instance.request;
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { HttpService } from './http.service';
export { HttpModule } from './http.module';
export { HttpService } from './http.service';
export * from './interfaces';
10 changes: 6 additions & 4 deletions lib/interfaces/http-module.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ModuleMetadata, Provider, Type } from '@nestjs/common';
import { AxiosRequestConfig } from 'axios';
import { IAxiosRetryConfig } from 'axios-retry';
import type { ModuleMetadata, Provider, Type } from '@nestjs/common';
import type { AxiosRequestConfig } from 'axios';
import type IAxiosRetry from 'axios-retry';

export type HttpModuleOptions = AxiosRequestConfig &
IAxiosRetryConfig & { isBetterStackTraceEnabled?: boolean };
IAxiosRetry.IAxiosRetryConfig & { isBetterStackTraceEnabled?: boolean };

export interface HttpModuleOptionsFactory {
createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions;
Expand All @@ -12,7 +12,9 @@ export interface HttpModuleOptionsFactory {
export interface HttpModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
useExisting?: Type<HttpModuleOptionsFactory>;
useClass?: Type<HttpModuleOptionsFactory>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
useFactory?: (...args: any[]) => Promise<HttpModuleOptions> | HttpModuleOptions;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
inject?: any[];
extraProviders?: Provider[];
}
Loading
Loading