From 270fa5b829a67a7cb1e003821b86017c874a1ba5 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 23 Dec 2021 19:20:41 +0200 Subject: [PATCH 01/12] using axios function signature --- lib/http.service.ts | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/http.service.ts b/lib/http.service.ts index e50abcf..6526732 100644 --- a/lib/http.service.ts +++ b/lib/http.service.ts @@ -1,34 +1,30 @@ import { Injectable } from '@nestjs/common'; import { Inject } from '@nestjs/common'; -import Axios ,{AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; +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; + constructor( @Inject(AXIOS_INSTANCE_TOKEN) private readonly instance: AxiosInstance = Axios, - ) {} - request(config: AxiosRequestConfig): Promise> { - return this.instance.request(config) - } - get(url: string, config?: AxiosRequestConfig): Promise> { - return this.instance.get(url, config); - } - delete(url: string, config?: AxiosRequestConfig): Promise> { - return this.instance.delete(url, config); - } - head(url: string, config?: AxiosRequestConfig): Promise> { - return this.instance.head(url, config); - } - post(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { - return this.instance.post(url, data, config); - } - put(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { - return this.instance.put(url, data, config); - } - patch(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { - return this.instance.patch(url, data, config); + ) { + 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 { From 8c9ac53b06de6441f79b9020b680cbcf36a409c6 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 23 Dec 2021 20:09:52 +0200 Subject: [PATCH 02/12] added better error stack trace --- lib/http.module.ts | 8 +++++--- package-lock.json | 10 ++++++++-- package.json | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/http.module.ts b/lib/http.module.ts index 065d4b7..a26a86b 100644 --- a/lib/http.module.ts +++ b/lib/http.module.ts @@ -13,10 +13,12 @@ import { HttpModuleOptionsFactory, } from './interfaces'; import axiosRetry from 'axios-retry'; +import axiosBetterStacktrace from 'axios-better-stacktrace'; -const createAxiosRetry = (config: HttpModuleOptions) => { +const createAxiosInstance = (config: HttpModuleOptions) => { const axiosInstance = Axios.create(config); axiosRetry(axiosInstance, config); + axiosBetterStacktrace(axiosInstance); return axiosInstance; } @@ -37,7 +39,7 @@ export class HttpModule { providers: [ { provide: AXIOS_INSTANCE_TOKEN, - useValue: createAxiosRetry(config), + useValue: createAxiosInstance(config), }, { provide: HTTP_MODULE_ID, @@ -55,7 +57,7 @@ export class HttpModule { ...this.createAsyncProviders(options), { provide: AXIOS_INSTANCE_TOKEN, - useFactory: (config: HttpModuleOptions) => createAxiosRetry(config), + useFactory: (config: HttpModuleOptions) => createAxiosInstance(config), inject: [HTTP_MODULE_OPTIONS], }, { diff --git a/package-lock.json b/package-lock.json index 13792fd..008d0cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nestjs-http-promise", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -486,7 +486,8 @@ "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true }, "ansi-styles": { "version": "4.3.0", @@ -562,6 +563,11 @@ "follow-redirects": "^1.14.4" } }, + "axios-better-stacktrace": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/axios-better-stacktrace/-/axios-better-stacktrace-2.1.2.tgz", + "integrity": "sha512-/ikpK5W7UhCAdl9pQss1vpTfLtOQpbv8edRZ2a9wWSux2dnGmqjVHkFsMKnyllysxm046C016lqGjUgGNECcag==" + }, "axios-retry": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/axios-retry/-/axios-retry-3.2.4.tgz", diff --git a/package.json b/package.json index 925c662..61ef73d 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "dependencies": { "axios": "~0.24.0", + "axios-better-stacktrace": "^2.1.2", "axios-retry": "^3.2.4" }, "devDependencies": { From 5db7ce730e4b89f0fae1138343266524758b7897 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 23 Dec 2021 23:57:32 +0200 Subject: [PATCH 03/12] added beta publish workflow --- .github/workflows/publish-beta.yml | 44 +++++++++++++++++++ .../{publish.yml => publish-master.yml} | 2 - 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-beta.yml rename .github/workflows/{publish.yml => publish-master.yml} (98%) diff --git a/.github/workflows/publish-beta.yml b/.github/workflows/publish-beta.yml new file mode 100644 index 0000000..6fd8950 --- /dev/null +++ b/.github/workflows/publish-beta.yml @@ -0,0 +1,44 @@ +name: publish-and-tag +env: + CI: true +on: + push: + branches: + - beta +jobs: + publish-to-npm: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + - name: setup Node + uses: actions/setup-node@v2 + with: + node-version: 14.x + registry-url: 'https://registry.npmjs.org' + - name: install + run: npm install + - name: test + run: npm test + # Publish to npm if this version is not published + - name: publish + run: npm run publish:beta + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + create-tag: + runs-on: ubuntu-latest + needs: publish-to-npm + steps: + - name: checkout + uses: actions/checkout@v2 + # Push tag to GitHub if package.json version's tag is not tagged + - name: package-version + run: node -p -e '`PACKAGE_VERSION=${require("./package.json").version}`' >> $GITHUB_ENV + - name: package-version-to-git-tag + uses: pkgdeps/git-tag-action@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + github_repo: ${{ github.repository }} + version: ${{ env.PACKAGE_VERSION }} + git_commit_sha: ${{ github.sha }} + git_tag_prefix: "v" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish-master.yml similarity index 98% rename from .github/workflows/publish.yml rename to .github/workflows/publish-master.yml index a8d3632..fa84185 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish-master.yml @@ -5,8 +5,6 @@ on: push: branches: - master - tags: - - "!*" jobs: publish-to-npm: runs-on: ubuntu-latest From be29c960cbcec1738ef3cc98f69193238934cb52 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 23 Dec 2021 23:58:12 +0200 Subject: [PATCH 04/12] removed create tag from beta workflow --- .github/workflows/publish-beta.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/publish-beta.yml b/.github/workflows/publish-beta.yml index 6fd8950..9ede483 100644 --- a/.github/workflows/publish-beta.yml +++ b/.github/workflows/publish-beta.yml @@ -24,21 +24,4 @@ jobs: - name: publish run: npm run publish:beta env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} - create-tag: - runs-on: ubuntu-latest - needs: publish-to-npm - steps: - - name: checkout - uses: actions/checkout@v2 - # Push tag to GitHub if package.json version's tag is not tagged - - name: package-version - run: node -p -e '`PACKAGE_VERSION=${require("./package.json").version}`' >> $GITHUB_ENV - - name: package-version-to-git-tag - uses: pkgdeps/git-tag-action@v2 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - github_repo: ${{ github.repository }} - version: ${{ env.PACKAGE_VERSION }} - git_commit_sha: ${{ github.sha }} - git_tag_prefix: "v" + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} \ No newline at end of file From ab17fc6b7dd6cc5faa3769fe5557a205cc7818c7 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 24 Dec 2021 00:01:37 +0200 Subject: [PATCH 05/12] removed beta workflow --- .github/workflows/publish-beta.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/publish-beta.yml diff --git a/.github/workflows/publish-beta.yml b/.github/workflows/publish-beta.yml deleted file mode 100644 index 9ede483..0000000 --- a/.github/workflows/publish-beta.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: publish-and-tag -env: - CI: true -on: - push: - branches: - - beta -jobs: - publish-to-npm: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v2 - - name: setup Node - uses: actions/setup-node@v2 - with: - node-version: 14.x - registry-url: 'https://registry.npmjs.org' - - name: install - run: npm install - - name: test - run: npm test - # Publish to npm if this version is not published - - name: publish - run: npm run publish:beta - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} \ No newline at end of file From 298af7a6389a86845fe52c00b8f5c531d398156a Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 24 Dec 2021 00:10:32 +0200 Subject: [PATCH 06/12] updated README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 89bcc9e..f19a168 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ nestjs module that just doing little modification to the original and good **nes ## features - * axios - the most used package for http requests in npm. + * axios - the most used package for http requests in npm and the one used by nestjs official http library. + * better axios stack trace - axios has an [open issue]((https://github.com/axios/axios/issues/2387)) about improvement of their stack trace. + in this library there is a default interceptor that will intercept the stack trace and will add data to it. + * promise - the most used package for http requests in npm and the one used by nestjs official http library. * promise based - most of us using the current http module that uses observable which we don't use most of the time and in order to avoid it were just calling `.toPromise()` every http call. * retries - in many cases we will want to retry a failing http call. From b6d468c2801eaa62e22ed2947fe4a85a10cc1afc Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 24 Dec 2021 00:11:56 +0200 Subject: [PATCH 07/12] fixed double brackets to one bracket in axios issue url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f19a168..3bf8a1f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ nestjs module that just doing little modification to the original and good **nes ## features * axios - the most used package for http requests in npm and the one used by nestjs official http library. - * better axios stack trace - axios has an [open issue]((https://github.com/axios/axios/issues/2387)) about improvement of their stack trace. + * better axios stack trace - axios has an [open issue](https://github.com/axios/axios/issues/2387) about improvement of their stack trace. in this library there is a default interceptor that will intercept the stack trace and will add data to it. * promise - the most used package for http requests in npm and the one used by nestjs official http library. * promise based - most of us using the current http module that uses observable which we don't use most of the time From f3e8f4186e46f84d02a5e772ce7a1d05f7c6ac1e Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 24 Dec 2021 00:13:08 +0200 Subject: [PATCH 08/12] renamed createAxiosRetry() to createAxiosInstance() --- lib/http.module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/http.module.ts b/lib/http.module.ts index e2d6ad1..d847236 100644 --- a/lib/http.module.ts +++ b/lib/http.module.ts @@ -15,7 +15,7 @@ import { import axiosRetry from 'axios-retry'; import axiosBetterStacktrace from 'axios-better-stacktrace'; -const createAxiosRetry = (config?: HttpModuleOptions) => { +const createAxiosInstance = (config?: HttpModuleOptions) => { const axiosInstance = Axios.create(config); axiosRetry(axiosInstance, config); axiosBetterStacktrace(axiosInstance); @@ -27,7 +27,7 @@ const createAxiosRetry = (config?: HttpModuleOptions) => { HttpService, { provide: AXIOS_INSTANCE_TOKEN, - useValue: createAxiosRetry(), + useValue: createAxiosInstance(), }, ], exports: [HttpService], From af3fe09510d4c6edf877878b3e9963d971475c4a Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 24 Dec 2021 00:17:18 +0200 Subject: [PATCH 09/12] added flag for better stack trace that by default is true --- lib/http.module.ts | 4 +++- lib/interfaces/http-module.interface.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/http.module.ts b/lib/http.module.ts index d847236..f85ecdb 100644 --- a/lib/http.module.ts +++ b/lib/http.module.ts @@ -18,7 +18,9 @@ import axiosBetterStacktrace from 'axios-better-stacktrace'; const createAxiosInstance = (config?: HttpModuleOptions) => { const axiosInstance = Axios.create(config); axiosRetry(axiosInstance, config); - axiosBetterStacktrace(axiosInstance); + if(config.isBetterStackTraceEnabled === undefined || config.isBetterStackTraceEnabled) { + axiosBetterStacktrace(axiosInstance); + } return axiosInstance; } diff --git a/lib/interfaces/http-module.interface.ts b/lib/interfaces/http-module.interface.ts index 1eee6f4..3875a3f 100644 --- a/lib/interfaces/http-module.interface.ts +++ b/lib/interfaces/http-module.interface.ts @@ -2,7 +2,7 @@ import { ModuleMetadata, Provider, Type } from '@nestjs/common'; import { AxiosRequestConfig } from 'axios'; import { IAxiosRetryConfig } from 'axios-retry' -export type HttpModuleOptions = (AxiosRequestConfig & IAxiosRetryConfig); +export type HttpModuleOptions = (AxiosRequestConfig & IAxiosRetryConfig & { isBetterStackTraceEnabled?: boolean }); export interface HttpModuleOptionsFactory { createHttpOptions(): Promise | HttpModuleOptions; From 9e36419537b7d16797c832fb372cdba97ec2735b Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 24 Dec 2021 00:18:51 +0200 Subject: [PATCH 10/12] removed redudant line from readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 3bf8a1f..eb84f83 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ nestjs module that just doing little modification to the original and good **nes * axios - the most used package for http requests in npm and the one used by nestjs official http library. * better axios stack trace - axios has an [open issue](https://github.com/axios/axios/issues/2387) about improvement of their stack trace. in this library there is a default interceptor that will intercept the stack trace and will add data to it. - * promise - the most used package for http requests in npm and the one used by nestjs official http library. * promise based - most of us using the current http module that uses observable which we don't use most of the time and in order to avoid it were just calling `.toPromise()` every http call. * retries - in many cases we will want to retry a failing http call. From 8748be1bb8989e3f2274abbd6ddb8a05f7b0217c Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 24 Dec 2021 00:21:11 +0200 Subject: [PATCH 11/12] updated in readme the default config --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb84f83..2fdee61 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,8 @@ import { HttpModule } from 'nestjs-http-promise' ``` ### default configuration - just the default config of axios-retry : https://github.com/softonic/axios-retry#options + * default config of axios-retry : https://github.com/softonic/axios-retry#options + * better axios stack trace is added by default, you can turn it off by passing the **isBetterStackTraceEnabled** to false. ## async configuration When you need to pass module options asynchronously instead of statically, use the `registerAsync()` method **just like in nest httpModule**. From 35d9e166e1056aef2dc58b029f64c6b2c0681bdf Mon Sep 17 00:00:00 2001 From: benhason1 <50466724+benhason1@users.noreply.github.com> Date: Fri, 24 Dec 2021 00:23:17 +0200 Subject: [PATCH 12/12] updated package json minor version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da41585..483308f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nestjs-http-promise", - "version": "1.1.1", + "version": "1.2.0", "keywords": [ "nestjs", "http",